Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christopher-baek/4781c6241e3a0c76ac57993044c8bbaf to your computer and use it in GitHub Desktop.
Save christopher-baek/4781c6241e3a0c76ac57993044c8bbaf to your computer and use it in GitHub Desktop.
NGINX, uWSGI, Flask Configuration Example
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')
# 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;
}
}
# 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;
}
}
# testing uwsgi configuration
uwsgi --socket 0.0.0.0:8000 --protocol=http -i basic.ini
# 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
[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