Web Application Setup - Nginx Set Up

webapp server nginx

NGINX SET UP

  1. Create your apps nginx configuration

    ... touch /var/www/appname/config/nginx-appname.cfg
    
  2. The content of your nginx-appname.cfg files should look like this:

    upstream appname {
        server unix:/var/run/uwsgi/appname.socket;
    }
    
    server {
    
        listen 80;
        server_name SERVER_IP SERVER_DOMAIN;
    
        location = /favicon.ico { access_log off; log_not_found off; }
    
        location /static/ {
            root /var/www/appname/;
        }
    
        location / {
            uwsgi_pass      appname;
            include         /etc/nginx/uwsgi_params;
        }
    
    }
    
  3. Link your nginx config file to nginx’ site config directory:

    ... cd /etc/nginx/sites-enabled
    ... ln -s /var/www/appname/config/appname-nginx.cfg appname
    
  4. You can check your nginx config by running the following:

    ... sudo nginx -t
    
  5. Make sure we have the firewall open for nginx:

    Check the available apps:

    ... sudo ufw app list
    Available applications:
      Nginx Full
      Nginx HTTP
      Nginx HTTPS
      OpenSSH
    ...
    

    Add one of the nginx options:

    ... sudo ufw allow 'Nginx Full'
    
    # enable the firewall 
    ... sudo ufw enable
    
  6. Restart nginx.

    ... sudo systemctl restart nginx
    

    After this you should be able to access your static files via a webbrowser.