首页  >  文章  >  后端开发  >  nginx 配置问题

nginx 配置问题

WBOY
WBOY原创
2016-09-24 09:15:111056浏览

<code class="nginx">location /admin/ {
            root   /aaa/dist;
            index  index.html;
        }</code>

举个栗子哈,比如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,那请问大家应该怎么配置呢?

回复内容:

<code class="nginx">location /admin/ {
            root   /aaa/dist;
            index  index.html;
        }</code>

举个栗子哈,比如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 {

<code>    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;
    }</code>

}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn