美文网首页
nginx的location配置项

nginx的location配置项

作者: 姜治宇 | 来源:发表于2024-07-28 15:53 被阅读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。

相关文章

网友评论

      本文标题:nginx的location配置项

      本文链接:https://www.haomeiwen.com/subject/pmkihjtx.html