TL;DR = Cannot get Passenger/Nginx to call our application from Django. "passenger-status" does not show proper Application Group that is shown in our currently live non-Docker server.
Trying to convert a live and running Passenger+Nginx+Django system to a Docker image. We started with the base Phusion:passenger-docker image and now trying to get it running like our live system. We followed the guide [here] but when we run the container, Passenger and Nginx do not run our application. Passenger provides the following output:
root@e8da5a56faec:/# passenger-status
Using /usr/local/rvm/gems/ruby-2.0.0-p648
Version : 5.1.2
Date : 2017-04-25 01:59:00 +0000
Instance: wXh9AKCm (nginx/1.10.2 Phusion_Passenger/5.1.2)
----------- General information -----------
Max pool size : 6
App groups : 0
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
root@e8da5a56faec:/#
--
root@e8da5a56faec:/# passenger-memory-stats
Using /usr/local/rvm/gems/ruby-2.0.0-p648
Version: 5.1.2
Date : 2017-04-25 01:59:49 +0000
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.
--------- Nginx processes ----------
PID PPID VMSize Private Name
------------------------------------
46 1 228.4 MB 0.7 MB nginx: master process /usr/sbin/nginx
49 46 228.4 MB ? nginx: worker process
1858 9 228.4 MB 3.5 MB /usr/sbin/nginx
### Processes: 3
### Total private dirty RSS: 4.13 MB (?)
---- Passenger processes ----
PID VMSize Private Name
-----------------------------
26 441.1 MB 1.2 MB Passenger watchdog
29 654.1 MB 2.9 MB Passenger core
35 449.3 MB ? Passenger ust-router
### Processes: 3
### Total private dirty RSS: 4.13 MB (?)
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user app;
#user nobody;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
include /etc/nginx/passenger.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
index index.html index.htm;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server_tokens off;
server {
listen 80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name yourserver.com;
root /home/app/public/;
passenger_enabled on;
passenger_python /usr/bin/python3.5;
ssl_certificate /etc/letsencrypt/live/yourserver.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/yourserver.com/privkey.pem; # managed by Certbot
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
add_header X-Frame-Options SAMEORIGIN;
location /static {
alias /home/app/src_django/assets;
}
}
}
FROM phusion/passenger-full
ENV NGINX_DIR=/etc/nginx
ENV APP=/home/app/webapp
ENV SCH_DIR=/your-scheduling
COPY ./nginx/nginx.conf $NGINX_DIR/
EXPOSE 80
EXPOSE 443
# Make SSL Cert directory
RUN mkdir -p /etc/letsencrypt/live/yourserver.com
# SSL Certs
COPY ./nginx/*.pem /etc/letsencrypt/live/yourserver.com/
# Random Passenger Stuff
ADD ./nginx/env.conf /etc/nginx/main.d/
ADD ./nginx/secret_key.conf /etc/nginx/main.d/
ADD ./nginx/gzip_max.conf /etc/nginx/conf.d/
# Get Code
COPY ./web $APP
COPY ./your-scheduling $SCH_DIR
# Install MySQL deps
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install -y libmysqlclient-dev
# Install Pip
RUN apt install -y python3-pip
# Run
RUN pip3 install -r $APP/requirements.txt
RUN python3.5 $APP/manage.py collectstatic --noinput
RUN cd /your-scheduling && python3.5 /your-scheduling/setup.py install && cd -
# Things because Passenger says so
RUN rm -f /etc/service/nginx/down
RUN rm -f /etc/nginx/sites-enabled/default
ADD ./nginx/webapp.conf /etc/nginx/sites-enabled/webapp.conf
# RUN mkdir /home/app/webapp
app:
restart: always
build: ./
links:
- mysql:mysql
environment:
YOUR_KEY_FILE: /home/app/webapp/src_django/keyfile.txt
DJANGO_SETTINGS_FILE: src_django.settings.settings
YOUR_PROD: "True"
PYTHONPATH: /home/app/webapp
mysql:
restart: always
image: mariadb:latest
ports:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: mydb
MYSQL_USER: db_user
MYSQL_PASSWORD: password
Hmmm... Try adding:
ports:
- 80:80
to the app
service.