1

Here is a service http://example.com based on port 4000 service, I can visit http://example.com/index.html now. When I visit http://example.com, I want it visit index.html too. Here is my nginx settings:

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
    listen   80;
    server_name example.com ;

    location / {
      root  /wwwroot/product/example.com/programs/web.broswer/app;
      index index.html;
      proxy_pass http://localhost:4000;         # 映射到本地端口
      #proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      # 配置支持websocket
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
    }
}

Now, the path / is not the resources of index.html.

1 Answer 1

0

The index directive will not work with a proxy_pass location. However, you can explicitly map / to /index.html with an exact match location, using:

location = / { rewrite ^ /index.html; }

to perform an internal redirect, or:

location = / { return 301 /index.html; }

to perform an external redirect.

See this and this for details.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .