my webapplication entirely dockerized and is written with a django and gunicorn backend and an nginx frontend. nginx is needed as a proxy and to serve static files.
nginx has access to the static files via mounted volume from django. I would like the entire frontend not as django templates.
i’m not understanding if index.html can be directly managed by nginx like this first configuration. (first nginx.conf)
or if the request should regardless firstly reach django and then, ascertained that the wanted file is a static file (index.html), be redirected with the url changed in /static/… so that can be caught by nginx. (second nginx.conf).
Thanks for everyone that will eventually help me.
Sorry if maybe my question is born out of ignorance and please feel free to teach me if needed.
server {
listen 443 ssl;
bash
Copy code
# SSL/TLS configuration
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;
# Define the location of static files
location / {
root /var/www/html/static/;
index index.html;
}
location /api/ {
include proxy_params;
proxy_pass http://backend:8000;
}
location /static/ {
alias /var/www/html/static/;
}
}
server {
listen 443 ssl;
bash
Copy code
# SSL/TLS configuration
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;
# Define the location of static files
location / {
proxy_pass http://backend:8000;
}
location /static/ {
alias /var/www/html/static/;
}
}
The second approch seems to make the work flow more fluent, but at the same time it seems like it does an useless step (going fistly on django just to be redirected, as if we dont know that would happen anyway).
Arianna Butnaru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.