前端 - 单页应用nginx配置
我想大声告诉你
我想大声告诉你 2017-05-16 17:23:07
[Linux讨论组]

我有个网站www.a.com
我希望访问www.a.com/**,
除了www.a.com/api/**的时候直接显示index.html
我的配置如下:

server {
    listen       80;
    server_name  www.a.com;

    location /api {
        proxy_pass http://localhost:8080/api;
        proxy_set_header Host $http_host;
    }
    location / {
        root   /usr/share/nginx/weather;
        index  index.html index.htm;
    }
}

现在遇到的问题是,
当我通过地址栏输入www.a.com/page1的时候,
我希望直接返回www.a.com/index.html,
但是现在却返回404!

我想大声告诉你
我想大声告诉你

全部回复(1)
淡淡烟草味

这个应该用rewrite
if($request_uri !~ ^api/.*){
rewrite $1/index.html break;
}

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

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