Run this script to setup a working NGINX server proxying requests to the gunicorn server.
- The script should run with
sudo
privilages. - Running the script:
sudo bash nginx_deploy.sh
- There must be a
NGINX server config file
should already present be present in the directory. - Sample config file used:
server_start
- The gunicorn server should already be running on
127.0.0.1
before running the script.
(Make sure that the address of gunicorn server and proxy pass adress is same)
Assuming that the gunicorn server is serving at 127.0.0.1:8888
server {
listen 5676;
server_name 0.0.0.0;
location / {
include proxy_params;
proxy_pass 127.0.0.1:8888;
}
}
Replace <script name>
with server_start
#!/usr/bin/env bash
# Making sure that the gunicorn server is already serving at localhost address
# Update and install packages
sudo apt-get update
sudo apt-get install python-pip python-dev nginx -y
echo "Packages installed..."
# cat file2 >> file1
# The >> operator appends the output to the named file or creates the named file if it does not exist.
# Remove any previously setup file of this name (to avoid any error)
sudo rm /etc/nginx/sites-enabled/<script name>
sudo rm /etc/nginx/sites-available/<script name>
# The directory must have the NGINX config file pre-made named server_config
sudo cat server_config >> /etc/nginx/sites-available/<script name>
echo " NGINX congiuration file created succesfully created"
# sudo cat server_config /etc/nginx/sites-available/myproject
sudo ln -s /etc/nginx/sites-available/<script name> /etc/nginx/sites-enabled
sudo nginx -t #add a if else condition here
echo "Tests succesfull!"
#server reastarted
sudo service nginx restart
echo "Server re-started! Should be serving now at the address in the config file!"
#NOTE: This would only serve the site at http:// (not at https://)