Nginx — static file serving confusion with root & alias

前端 未结 7 1251
[愿得一人]
[愿得一人] 2020-11-22 15:29

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

7条回答
  •  温柔的废话
    2020-11-22 16:06

    Just a quick addendum to @good_computer's very helpful answer, I wanted to replace to root of the URL with a folder, but only if it matched a subfolder containing static files (which I wanted to retain as part of the path).

    For example if file requested is in /app/js or /app/css, look in /app/location/public/[that folder].

    I got this to work using a regex.

     location ~ ^/app/((images/|stylesheets/|javascripts/).*)$ {
         alias /home/user/sites/app/public/$1;
         access_log off;
         expires max;
     }
    

提交回复
热议问题