首页 > 解决方案 > Nginx:位置=/不使用位置/

问题描述

我有一个包含两个位置的 nginx 主机文件,我想让确切的 / 转到 index.html 和 /something 转到我的代理。

我有一个要用于 my_domain.com 的 HTML 登录页面,并且我的 React 应用程序在代理通行证中提供,所以我希望 my_domain.com/something 指向我的代理(反应应用程序)。

上面使用的东西可以是任何字符串

我已经尝试过了,但它不起作用它总是重定向到我的第二个位置:

server_name domain.com www.domain.com;
index index.php index.html index.htm;

location = / {
    root /var/www/domain;
    index index.html;
    try_files $uri /index.html;
}

location / {
    proxy_pass http://localhost:3020;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

我希望你能帮助我。

谢谢。

标签: nginx

解决方案


推荐阅读