流星,NGINX子路径错误

METEOR, NGINX subpath error

本文关键字:路径 错误 NGINX 流星      更新时间:2023-09-26

我有一个应用程序部署了nginx和docker,现在我添加了第二个应用程序也与docker,所以,这将是情况

DOCKER_METEOR_APP1

DOCKER_METEOR_APP2

在同一个服务器SERVER_IP

http://SERVER_IP/DOCKER_METEOR_APP1

http://SERVER_IP/DOCKER_METEOR_APP2

我的NGINX配置是:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
# HTTP
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    root /usr/share/nginx/html;
    index index.html index.htm;
    server_name MY_COOL_SERVER;
    location /DOCKER_METEOR_APP1 {
        proxy_pass http://SERVER_IP:8001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
        if ($uri != '/') {
            expires 30d;
        }
    }
    location /DOCKER_METEOR_APP2 {
        proxy_pass http://SERVER_IP:8002;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
        if ($uri != '/') {
            expires 30d;
        }
    }
}

每次我尝试访问一个或其他应用程序,我得到页面标题和错误…它似乎试图从根路径加载内容,比如

http://SERVER_IP.com/hjas867651877e1u9812931.css?..。

我做错了什么?有解决办法吗?

好了…我对这个问题的解决方案

  • 上的每个应用添加了ROOT_URL

ENV ROOT_URL http://127.0.0.1/DOCKER_METEOR_APP1

  • 同样,在lib/startup.js

Meteor.startup(function() { process.env.ROOT_URL = 'http://127.0.0.1/DOCKER_METEOR_APP1/'; });

  • …在我的react路由器上得到这个:

const history = useBasename( createHistory )( { basename: '/DOCKER_METEOR_APP1' } )

<Router history={history}>