php - nginx 配置问题
巴扎黑
巴扎黑 2017-04-11 10:29:05
[PHP讨论组]
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,那请问大家应该怎么配置呢?

巴扎黑
巴扎黑

全部回复(3)
ringa_lee

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

}

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号