1
votes

I run nginx as a reverse proxy server in front of apache. I need to access uploaded files from frontend in backend so the way to go is to use an alias in nginx site config but static files in backend should be handled directly by nginx. I'm new to nginx so here is my partial config that handles static files. I also specified an alias (/images) but it will not work because it is overwritten by second condition. How can the two conditions be combined so that nginx handles static files from root (backend app) and uploaded files from frontend app. In apache config I included an alias for this problem and it works but without nginx in front.

Here is my partial nginx config:

  server {
       listen 80;

       root /var/www/website/backend/www;

       # Add index.php to the list if you are using PHP
       index index.html index.php index.htm;

       server_name admin.website.com www.admin.website.com;

       location / {
                proxy_pass http://localhost:8080;
                include /etc/nginx/proxy_params;
       }
#The alias to handle uploaded files(.jpeg, .pdf) from frontend
      location  /images {
               alias /var/www/website/frontend/www/images;
      }
#let nginx handle static files from root
       location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
               expires      30d;
       }
.
.
.
}
1

1 Answers

1
votes

The regular expression location block takes precedence over a prefix location block (unless the ^~ modifier is used). See this document for details.

Try:

location ^~ /images {
    root /var/www/website/frontend/www;
}

Note that the root directive is preferred in this case (see this document for details)