Heim  >  Artikel  >  Backend-Entwicklung  >  nginx 配置问题

nginx 配置问题

WBOY
WBOYOriginal
2016-09-24 09:15:111056Durchsuche

<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>

}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn