-
-
Save d3cline/31cfd9a1fc717f32d30289836cc6c334 to your computer and use it in GitHub Desktop.
A simple 'hello world' python application with uwsgi and nginx
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
# A simple 'hello world' application with python uwsgi and nginx | |
# Make directory and files | |
# The directory structure: | |
# ./ | |
# |-- app/ | |
# | |-- hello.py | |
# | |-- hello_nginx.conf | |
if [ -d app ]; then | |
rm -rf app | |
fi | |
mkdir app/ | |
touch app/hello.py | |
touch app/hello_nginx.conf | |
# Define the port | |
port=3031 | |
# A single Python function called 'application' is saved in 'app/hello.py', | |
# and it would be loaded by uWSGI Python as the default function. | |
echo "def application(env, start_response): | |
start_response('200 OK', [('Content-Type','text/html')]) | |
return [b\"Hello World!\"]" > app/hello.py | |
# A common nginx config is saved in 'app/hello_nginx.conf'. | |
# Use the 80 port. | |
echo 'server { | |
listen 80 default_server; | |
server_name localhost; | |
location / { | |
include uwsgi_params; | |
uwsgi_pass 127.0.0.1:'${port}'; | |
} | |
}' > app/hello_nginx.conf | |
# Create a softlink | |
ln -sf `pwd`/app/hello_nginx.conf /etc/nginx/sites-enabled/ | |
# resart nginx | |
service nginx restart | |
# Free the port | |
fuser -k ${port}/tcp | |
# start uwsgi | |
uwsgi --socket 127.0.0.1:${port} --wsgi-file app/hello.py --pidfile /tmp/hello.pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment