单页应用nginx配置

我有个网站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!

阅读 7.8k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题