使用Nginx反向代理子目录导致路径问题

问题描述 投票:0回答:0

我现在正尝试通过 Nginx 反向代理我的 SolidJS 应用程序。

我的应用程序在 3000 端口上运行。 (http://example.com:3000)

但是,我想将这个应用程序反向代理到子目录(https://example.com/myapp

nginx 在使用根目录 (https://example.com/) 时正常工作,但它不能正确加载子目录的页面。

我在互联网上尝试了几种解决方案,但没有一个对我有帮助。以下代码是我尝试过的事情之一。

location /myapp/ {
  rewrite ^/myapp/(.*)$ /$1 break;
  proxy_pass http://example.com:3000/;
}
server {
  listen 80;
  server_name example.com;

  location /myapp {
    proxy_pass http://example.com:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;

    # Set the base URL of the React app
    proxy_set_header X-Forwarded-Host example.com;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Path /myapp;
  }
}

如果有其他解决方案,我会尝试。

reactjs nginx reverse-proxy solid-js
© www.soinside.com 2019 - 2024. All rights reserved.