Created
April 25, 2019 14:59
-
-
Save amites/f67a1bcda661d70bc6e5bbe2dd71b860 to your computer and use it in GitHub Desktop.
Nginx & Gunicorn Boilerplate Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name DOMAIN, *.DOMAIN; | |
location = /favicon.ico {access_log off; log_not_found off; } | |
location /static/ { | |
root /PATH/TO/PROJECT/ROOT; | |
} | |
location / { | |
include proxy_params; | |
proxy_pass http://unix:/PATH/TO/PROJECT/ROOT/PROJECTNAME.sock; | |
} | |
client_max_body_size 50M; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Gunicorn PROJECTNAME Daemon | |
After=network.target | |
[Service] | |
User=VALIDUSER | |
Group=www-data | |
WorkingDirectory=/PATH/TO/PROJECT/ROOT | |
ExecStart=/PATH/TO/GUNICORN/bin/gunicorn --workers 3 --bind unix:/PATH/TO/PROJECT/ROOT/PROJECTNAME.sock PROJECTDIR.wsgi:application | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recommend updating file names to match project to avoid confusion, anything written in UPPERCASE is meant to be replaced
ie
VALIDUSER
could beubuntu
or any other system user with appropriate permissionsabove assumes that
VALIDUSER
belongs to groupwww-data
usermod -a -G www-data VALIDUSER
If running Ubuntu for your server
nginx.conf
will goto/etc/nginx.sites-available
and create a symlinkln -s /etc/nginx/sites-available/nginx.conf /etc/nginx/sites-enabled
for systemd to daemonize the gunicorn instance place
PROJECT.service
under directory/etc/systemd/system/
update appropriate names
to test the service will work run the updated line from
ExecStart
in the console as the chosenVALIDUSER
sudo -u VALIDUSER /PATH/TO/GUNICORN/bin/gunicorn --workers 3 --bind unix:/PATH/TO/PROJECT/ROOT/PROJECTNAME.sock PROJECTDIR.wsgi:application
after verifying that works correctly
run
systemctl daemon-reload
to load the new servicerun
systemctl start PROJECT
to start the service manuallyyou can verify it's running with
ps aux | grep gunicorn
the above config will have multiple instances running, if not try running the command mannually
to make it auto-start on reboot of server
systemctl enable PROJECT