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 hidden or 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 hidden or 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 |
Author
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
VALIDUSERcould beubuntuor any other system user with appropriate permissionsabove assumes that
VALIDUSERbelongs to groupwww-datausermod -a -G www-data VALIDUSERIf running Ubuntu for your server
nginx.confwill goto/etc/nginx.sites-availableand create a symlinkln -s /etc/nginx/sites-available/nginx.conf /etc/nginx/sites-enabledfor systemd to daemonize the gunicorn instance place
PROJECT.serviceunder directory/etc/systemd/system/update appropriate names
to test the service will work run the updated line from
ExecStartin the console as the chosenVALIDUSERsudo -u VALIDUSER /PATH/TO/GUNICORN/bin/gunicorn --workers 3 --bind unix:/PATH/TO/PROJECT/ROOT/PROJECTNAME.sock PROJECTDIR.wsgi:applicationafter verifying that works correctly
run
systemctl daemon-reloadto load the new servicerun
systemctl start PROJECTto start the service manuallyyou can verify it's running with
ps aux | grep gunicornthe 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