Last active
April 3, 2016 21:40
-
-
Save christopher-baek/4781c6241e3a0c76ac57993044c8bbaf to your computer and use it in GitHub Desktop.
NGINX, uWSGI, Flask Configuration Example
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
from flask import Flask | |
my_app = Flask(__name__) | |
@my_app.route('/') | |
def hello_world(): | |
return 'Hello World!' | |
if __name__ == '__main__': | |
my_app.run(host='0.0.0.0') |
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
# basic nginx configuration (serving app from root) | |
server { | |
listen 80; | |
server_tokens off; | |
server_name www.myapp.com myapp.com; | |
location / { | |
include uwsgi_params; | |
uwsgi_pass unix:/tmp/my_app.sock; | |
} | |
location /static { | |
alias /var/www/my_app/static; | |
} | |
if ($host !~ ^(myapp.com|www.myapp.com)$ ) { | |
return 444; | |
} | |
} |
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
# basic nginx configuration (serving app from root) | |
server { | |
listen 80; | |
server_tokens off; | |
server_name www.myapp.com myapp.com; | |
# mounting under a subdirectory in nginx | |
location /my_app { | |
include uwsgi_params; | |
uwsgi_pass unix:/tmp/my_app.sock; | |
uwsgi_param SCRIPT_NAME /my_app; | |
uwsgi_modifier1 30; | |
} | |
location /static { | |
alias /var/www/my_app/static; | |
} | |
if ($host !~ ^(myapp.com|www.myapp.com)$ ) { | |
return 444; | |
} | |
} |
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
# testing uwsgi configuration | |
uwsgi --socket 0.0.0.0:8000 --protocol=http -i basic.ini |
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
# other performance and security configurations | |
[uwsgi] | |
module = app | |
callable = my_app | |
master = true | |
processes = 5 | |
socket = /tmp/my_app.sock | |
chmod-socket = 660 | |
vacuum = true | |
die-on-term = true |
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
[uwsgi] | |
vhost = true | |
socket = /tmp/my_app.sock | |
venv = /var/www/my_app/.env | |
chdir = /var/www/my_app | |
module = app | |
callable = my_app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment