nginx的location配置项

2024-07-28  本文已影响0人  姜治宇

比如有这样一个angular的站点,当我点击选项卡时,会请求这个类别的图片信息。而这些图片并未放在前端本地目录src/assets下,而是在另外一个单独的目录/usr/share/files下面,那如何通过nginx做映射呢?


我们可以定一个关键词img,凡是http://xxx.com/img/a.png这样的信息,都可以去单独的目录/usr/share/files下面去找,其他仍映射到angular目录 。

    server {
       listen       80;
       server_name  localhost;
       location / {
            root /home/angular;
            index index.html index.htm;
       }
       location /img {
           alias   /usr/share/files;
           index  index.html index.htm;
       }

       
    }

一定注意要用alias关键字,而不是root。

上一篇 下一篇

猜你喜欢

热点阅读