Home  >  Q&A  >  body text

Front-end - single-page application nginx configuration

I have a website www.a.com
I want to visit www.a.com/**,
Except when www.a.com/api/**, index.html
is displayed directly. My configuration is as follows:

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

The problem we are encountering now is,
When I enter www.a.com/page1 through the address bar,
I want to return directly to www.a.com/index.html,
But now it returns 404!

我想大声告诉你我想大声告诉你2713 days ago530

reply all(1)I'll reply

  • 淡淡烟草味

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

    You should use rewrite for this
    if($request_uri !~ ^api/.*){
    rewrite $1/index.html break;
    }

    reply
    0
  • Cancelreply