Created
October 1, 2014 13:20
-
-
Save NickWoodhams/4a845c7aeec8e7d1653d to your computer and use it in GitHub Desktop.
Quickly create matching Nginx and UWSGI app configs
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
#!/bin/sh | |
#creates nginx and uwsgi files and enables sites | |
echo "------------------Add-App------------------" | |
echo "What is the ABSOLUTE PATH of your WSGI file? " | |
read wsgi_path | |
app_home=$(dirname "$wsgi_path") | |
echo "Using $app_home for your App Directory." | |
echo "Using $app_home/venv for your Virtualenv." | |
echo "What is your application domain name? " | |
read domain_name | |
echo "Creating nginx config file at /etc/nginx/sites-available/${domain_name}" | |
sudo tee /etc/nginx/sites-available/${domain_name} > /dev/null <<EOF | |
server { | |
listen 80; | |
server_name .${domain_name}; | |
root ${app_home}; | |
location / { | |
include /etc/nginx/uwsgi_params; | |
uwsgi_pass unix:/tmp/${domain_name}.sock; | |
} | |
} | |
EOF | |
echo "Creating UWSGI config file at /etc/uwsgi/apps-available/${domain_name}.ini" | |
sudo tee /etc/uwsgi/apps-available/${domain_name}.ini > /dev/null <<EOF | |
[uwsgi] | |
master = true | |
enable-threads = true | |
base = ${app_home} | |
file = ${wsgi_path} | |
plugins = http,python | |
home = %(base)/venv | |
pythonpath = %(base) | |
socket = /tmp/%n.sock | |
logto = /var/log/uwsgi/%n.log | |
workers = 3 | |
buffer-size = 32768 | |
EOF | |
echo "Enabling Nginx and UWSGI apps" | |
sudo ln -s /etc/nginx/sites-available/${domain_name} /etc/nginx/sites-enabled/${domain_name} | |
sudo ln -s /etc/uwsgi/apps-available/${domain_name}.ini /etc/uwsgi/apps-enabled/${domain_name}.ini | |
sudo service uwsgi restart | |
sudo service nginx restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment