Skip to content

Instantly share code, notes, and snippets.

@KavenTheriault
Last active November 23, 2021 23:28
Show Gist options
  • Save KavenTheriault/8df5a613d7087767bdc01593c724bc7f to your computer and use it in GitHub Desktop.
Save KavenTheriault/8df5a613d7087767bdc01593c724bc7f to your computer and use it in GitHub Desktop.
ArchLinux nginx+uwsgi+flask
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"

Dependencies

$ pacman -S python-pip nginx uwsgi-plugin-python uwsgi

Directories

$ /etc/nginx/ (nginx directory)
$ /etc/uwsgi/ (uwsgi directory)
$ /usr/share/nginx/uswgi_test/ (app directory)

Init test app

# override ngnix.conf in /etc/nginx/

$ cd /usr/share/nginx/uswgi_test/

$ mkdir log
$ cd log
$ touch uswgi_test.log
$ sudo chmod 777 uswgi_test.log

# create hello.py
# create uwsgi_test.nginx.conf

$ virtualenv venv
$ source venv/bin/activate

(venv) $ pip install flask
or
(venv) $ pip install -r requirements.txt

$ deactivate
$ sudo chown http:http -R /usr/share/nginx/uswgi_test/

$ cd /etc/uwsgi/
# create uwsgi_test.ini

$ systemctl start nginx.service
$ systemctl start uwsgi@uswgi_test.service

Test command

$ uwsgi --http :8000 --plugin python --wsgi-file hello.py --callable app -H /usr/share/nginx/uwsgi_test/venv

Run command

$ uwsgi --ini uwsgi_test.uwsgi.ini
user http;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
include /usr/share/nginx/*/*.nginx.conf;
}
[uwsgi]
module = hello
callable = app
plugin = python
chdir = /usr/share/nginx/uwsgi_test/
socket = /tmp/uwsgi_test.uwsgi.sock
virtualenv = /usr/share/nginx/uwsgi_test/venv
logto = /usr/share/nginx/uwsgi_test/log/%n.log
chmod-socket = 666
uid = http
gid = http
server {
listen 80;
server_name localhost;
root /usr/share/nginx/uwsgi_test/;
error_log /usr/share/nginx/uwsgi_test/log/error.log;
access_log /usr/share/nginx/uwsgi_test/log/access.log;
location / {
try_files $uri @context;
}
location @context {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi_test.uwsgi.sock;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment