I need to serve my app through my app server at 8080
, and my static files from a directory without touching the app server. The nginx config I have is something like this...
# app server on port 8080
# nginx listens on port 8123
server {
listen 8123;
access_log off;
location /static/ {
# root /var/www/app/static/;
alias /var/www/app/static/;
autoindex off;
}
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;
}
}
Now, with this config, everything is working fine. Note that the root
directive is commented out.
If I activate root
and deactivate the alias
-- it stops working. However, when I remove the trailing /static/
from the root
it starts working again.
Can someone explain what's going on. Also please explain clearly and verbosely what are the differences between root
and alias
, and their purposes.