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
Asked
Active
Viewed 42 times
0

Nursultan Ergeshov
- 61
- 1
- 6
1 Answers
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
-
1Thank you a lot! I already solved my problem... I just forgot to set the volume for django app)) – Nursultan Ergeshov Oct 16 '19 at 07:48