首頁  >  問答  >  主體

前端 - 單頁應用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!

我想大声告诉你我想大声告诉你2713 天前522

全部回覆(1)我來回復

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:25:07

    這個應該用rewrite
    if($request_uri !~ ^api/.*){
    rewrite $1/index.html break;
    }

    回覆
    0
  • 取消回覆