Skip to content

Instantly share code, notes, and snippets.

@paneru-rajan
Last active June 1, 2018 06:58
Show Gist options
  • Save paneru-rajan/2e3fd4aa9044ead21e2061027ee8dff4 to your computer and use it in GitHub Desktop.
Save paneru-rajan/2e3fd4aa9044ead21e2061027ee8dff4 to your computer and use it in GitHub Desktop.
[Nginx configuration for django] It serves static file from different folder #nginx #django #proxy

Nginx proxy configuration for django applications.

  1. Create a file
    vim /etc/nginx/sites-available/<filename>
    
  2. Paste below content and edit accordingly
    server {
        listen       80;
        server_name  test.django.com;
    
        location /static/ {
            root /var/www/test.django.com/;
        }
    
        location / {
            proxy_pass http://127.0.0.1:8080/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    
  3. create a smlink to sites-enabled
    sudo ln -s /etc/nginx/sites-available/<filename> /etc/nginx/sites-enabled
    
  4. Check nginx configuration and reload
    sudo nginx -t
    sudo service nginx reload
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment