【问题标题】:Nginx config for Meteor deployment用于 Meteor 部署的 Nginx 配置
【发布时间】:2016-04-26 10:23:04
【问题描述】:

我的问题是如何让 Nginx 将域 (www.example.com/app) 转发到同一服务器上的流星应用程序。 Nginx 运行在 80 端口,Meteor 运行在同一台机器的 4000 端口。

以下是详细信息:我正在尝试使用 Nginx 在我自己的服务器上托管由流星制作的应用程序。我似乎无法让 Nginx 将我的域名转发到端口 4000,meteor 可以在那里获取并处理网页。

Nginx 代理端口的最新配置是这样的:

server {
    listen 80 default_server;
    listen [::]: 80 default_server ipv6only = on;
    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
        try_files $uri $uri / = 404;    
    }

    location /app {
        rewrite ^/app(.*) /$1 break;
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header X-Forwarded-For $remote_addr;
   }
}

当我在

访问流星应用程序时使用此配置

www.example.com/app

所有 *.js 和 *.css 文件请求都被转发到

www.example.com/xxxxxxxxxxxx.js

应该是这样的

www.example.com/app/xxxxxxxxxxxx.js

有人可以解释一下我在 Nginx 配置或 Meteor 配置中缺少什么以将我的流星应用程序指向

www.example.com/app

【问题讨论】:

标签: javascript node.js meteor nginx server


【解决方案1】:

删除这一行:

    rewrite ^/app(.*) /$1 break;

它将像 www.example.com/app/xxxxxxxxxxxx.js 这样的 URL 转换回 www.example.com/xxxxxxxxxxxx.js

【讨论】:

  • rewrite 是必需的,因为流星(或 node.js)应用程序服务于来自/而不是来自 '/app' 的请求,因此 ngnix 必须将请求转发到 127.0.0.1:4000
猜你喜欢
  • 2014-02-12
  • 2012-09-13
  • 1970-01-01
  • 2015-01-12
  • 1970-01-01
  • 2019-02-15
  • 2014-08-13
  • 1970-01-01
  • 2018-02-03
相关资源
最近更新 更多