nginx 配置问题

php教程评论75 views阅读模式
location /admin/ {
            root   /aaa/dist;
            index  index.html;
        }

举个栗子哈,比如nginx里有上面这个配置,假设域名是a.com。
那么我访问a.com/admin/index.html的时候nginx会去这个目录加载这个静态html:/aaa/dist/admin/index.html
现在如果我希望用/admin/后面的url去寻找静态文件那应该怎么配置呢?就是我现在希望这个已经匹配上的/admin/部分,在查找静态文件的时候不要再出现在路径里面了,比如还是上面的url,a.com/admin/index.html,我希望nginx能直接拿后面的url去root目录寻找,也就是寻找/aaa/dist/index.html,那请问大家应该怎么配置呢?

回复内容:

location /admin/ {
            root   /aaa/dist;
            index  index.html;
        }

举个栗子哈,比如nginx里有上面这个配置,假设域名是a.com。
那么我访问a.com/admin/index.html的时候nginx会去这个目录加载这个静态html:/aaa/dist/admin/index.html
现在如果我希望用/admin/后面的url去寻找静态文件那应该怎么配置呢?就是我现在希望这个已经匹配上的/admin/部分,在查找静态文件的时候不要再出现在路径里面了,比如还是上面的url,a.com/admin/index.html,我希望nginx能直接拿后面的url去root目录寻找,也就是寻找/aaa/dist/index.html,那请问大家应该怎么配置呢?

root 改成alias 试试
alias /aaa/dist/;

最简单的方式,在/aaa/dist/admin/index.html做一个软连接到/aaa/dist/index.html

server {

    listen          80;
    server_name     demo.test.com;
    index           index.php index.html;
    root            /mnt/hgfs/leyvi/demo.test.com/pubilc;

    location ~.*\.(php)?$
    {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            include         fastcgi.conf;
    }

}

企鹅博客
  • 本文由 发表于 2020年10月5日 04:17:44
  • 转载请务必保留本文链接:https://www.qieseo.com/229100.html

发表评论