Reputation: 490
I have a Flask app that I'm trying to host with Gunicorn and Nginx. I've followed several tutorials and I cannot seem to get Nginx to stop rendering the "Welcome to Nginx" page.
I've already confirmed that Supervisor successfully launches three Gunicorn workers, and Nginx is running in the background as well. SSL is confirmed working and Nginx picks up traffic on port 443. I've attempted to add Nginx to the same group as the user who owns the sock shared by Gunicorn and Nginx.
This is the bash script which Supervisor uses to start Gunicorn. This is confirmed working.
#!/bin/bash
NAME="Simon"
FLASKDIR=/var/www/Simon
SOCKFILE=/var/www/Simon/simon.sock
USER=glen
GROUP=glen
NUM_WORKERS=3
FLASK_SETTINGS_MODULE=config.py
FLASK_WSGI_MODULE=Simon.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $FLASKDIR
source Simon/bin/activate
export FLASK_SETTINGS_MODULE=$FLASK_SETTINGS_MODULE
export PYTHONPATH=$FLASKDIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec gunicorn Simon:simon \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
This the site config:
upstream simon_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/var/www/Simon/simon.sock fail_timeout=0;
}
server {
listen 443 ssl;
server_name glencoverx.com;
client_max_body_size 4G;
access_log /var/www/Simon/logs/nginx-access.log;
error_log /var/www/Simon/logs/nginx-error.log;
location /static/ {
alias /var/www/Simon/static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
if ($scheme != "https") {
return 301 https://$host$request_uri;}
}
ssl_certificate /etc/letsencrypt/live/glencoverx.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/glencoverx.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}
Weirdly enough, the logs show no problems. I've completely deleted the Nginx default site config and removed its symlink. I don't understand why Nginx will not communicate with Gunicorn.
Upvotes: 0
Views: 1659
Reputation: 15
first it would be helpful if you would do something like:
listen 443 default ssl;
This will make that site default.
If you haven't already, service nginx restart
and make sure that your cache is purged. Try using telnet to do a get to make sure that it's still enabled.
Check your nginx/conf.d and sites-enabled dirs to see if the symlink or the default website is still there.
Upvotes: 0