0

I'm setting up a new server and running Django application via docker run -p 8000:8000 --name=somename etc. So now I need to configure NGINX to serve static files of my Django application

1 Answers1

0

Nginx is a proxy server so you will have to put it before your Django application. All the request to your Django app will pass through the nginx server. So if your Django application is running on port 8000 you will run nginx which will proxy_pass (meaning redirect) all the non-static asset routes to DjangoAppIPAddress:8000. Here is an example nginx conf file for doing this:

server {
    ...
    location /uri/for/static/content {
       root /path/to/your/static/files
    }
    location /uri/for/dynamic/content {
       proxy_pass DjangoAppIPAddress:8000
    }
}

If you are doing this in a cloud environment then I would suggest you create two different pods. One for the django app and another one for nginx and expose only the nginx pod outside the cluster.

Yogeshwar Singh
  • 1,245
  • 1
  • 10
  • 22