Nginx — static file serving confusion with root & alias

前端 未结 7 1319
[愿得一人]
[愿得一人] 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:18

    In your case, you can use root directive, because $uri part of the location directive is the same with last root directive part.

    Nginx documentation advices it as well:
    When location matches the last part of the directive’s value:

    location /images/ {
        alias /data/w3/images/;
    }
    

    it is better to use the root directive instead:

    location /images/ {
        root /data/w3;
    }
    

    and root directive will append $uri to the path.

提交回复
热议问题