Node.js 如何使用NGINX重定向除主页之外的所有页面?

Node.js 如何使用NGINX重定向除主页之外的所有页面?,node.js,nginx,Node.js,Nginx,这是我的NGINX conf文件: server { listen 80; listen [::]:80; server_name other.com; root /home/user/html; location = / { } location / { return 301 https://mydom.com$request_uri; } } 它假设重定

这是我的NGINX conf文件:

server {
    listen 80;
    listen [::]:80;
    server_name other.com;
    root        /home/user/html;

        location = / {

        }

        location / {
           return 301 https://mydom.com$request_uri;
        }
}

它假设重定向除主路由(“/”)之外的每个请求。但现在它也用主路线重定向所有东西。我的错在哪里

Your
location=/
块隔离单个URI—原始请求

默认情况下,Nginx处理以
/
结尾的任何请求,方法是检查请求是否解析为目录,并检查目录中是否有与
index
指令中列出的文件匹配的任何文件(默认值:
index.html

index
指令导致内部重定向,从而导致Nginx重复搜索匹配的
位置

您还需要隔离重定向的请求

例如:

location = / { }
location = /index.html { }
location / { ... }
location = / { try_files /index.html =404; }
location / { ... }

或者,绕过
index
指令,使用
try\u files
语句将其处理为单个
位置

例如:

location = / { }
location = /index.html { }
location / { ... }
location = / { try_files /index.html =404; }
location / { ... }

有关详细信息,请参阅。

查看您的配置,URI
/
将在内部重定向到
/index.html
。您还需要添加
location=/index.html{}
块。是的。绝对正确!