nginx和meteorjs - 如何重写URL以包含端口?

时间:2015-10-31 01:12:49

标签: meteor nginx

我对如何重写http地址为http://IP/<LettersHere>meteor_js_resource=truehttp://IP:3000/<LettersHere>meteor_js_resource=true的meteorjs请求的网址感到困惑。

如果我访问我网站的网址:3000,那么我可以从流星应用程序中获取所有静态文件。

enter image description here

但是,如果我尝试使用此nginx配置文件将URL:3000路由到URL/someURL,那么当人们访问我的网站时,他们不需要3000端口号,而是需要/someURL

server {
    listen 0.0.0.0:80;

    server_name domain.com;

    location /youtube-channel-search 
    {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://localhost:3000;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      rewrite http://domain.com http://domain.com:3000 permanent;
    }
}

然后我收到一个无法找到js文件的错误:

enter image description here

这是正确的,因为http://IP/URL不是http://IP:3000/URL

我应该如何重写传入的请求以添加额外的端口:3000?我认为proxy_pass会自动处理这个问题。

由于

1 个答案:

答案 0 :(得分:1)

我明白了。

您需要将meteorJS应用程序的ROOT_URL环境参数更改为localhost:3000/youtube-channel-search

使用相同的nginx.conf可以正常工作。

这是因为某些sockjs和静态文件被映射到localhost:3000,没有尾随/youtube-channel-search