Nginx 未加载 Meteor 包:出现 404 错误
Nginx not loading Meteor packages : Getting 404 error
这就是我想要完成的……我正在尝试在我的开发机器上使用 nginx 设置一个反向代理服务器,并在不同的本地端口上本地托管三个流星应用程序。我希望我的 nginx 根据虚拟目录重定向请求...像 localhost/App1 会重定向到 localhost:3010 而 localhost/App2 会重定向到 localhost:3011。这些应用程序将需要使用 Meteor Identity 微服务(第三个应用程序)进行身份验证,并且这些应用程序将需要使用 localhost/Iden 之类的东西来重定向未经身份验证的用户
作为第一步,我有这个设置:
我正在尝试在本地 Nginx 上部署 app1 Meteor 应用程序。我已经使用 "meteor build" 构建了应用程序并将内容移动到我的根目录所在的 Nginx/html。通过 nginx 端口 (localhost:81) 浏览应用程序后,我无法加载任何流星包,但能够加载应用程序文件。该应用程序本身是 运行 localhost:3000
错误如下
Error screenshot : Chrome console
我可以单独浏览我创建的资源文件,例如 todo.js
localhost:81/app/template.todo1.js?979b20f66caf126704c250fbd29ce253c6cb490e
但我无法浏览到 meteor 包文件
localhost:81/packages/global-imports.js?af67437fd606dadafb22ec5e8bfc6ca8314a60ad
因为它 returns 404
下面是我的 nginx 配置
#user nginx;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 0.0.0.0:81;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~* "^/[a-z0-9]{60}\.(css|js)$" {
root /app1/bundle/programs/server;
access_log off;
expires max;
}
location ~ "^/packages" {
root /app1/bundle/programs/server;
access_log off;
}
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /app1/bundle/programs/server;
access_log off;
expires max;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
#proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
location /app2 {
proxy_pass http://127.0.0.1:3010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
#proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
感谢任何帮助,因为我从昨天开始就在努力解决这个问题
如果您只需要反向代理,那么我建议使用 redbird:
npm install redbird
然后,例如,如果您有两个 meteor 应用 运行在本地端口 3000 和 4000 上:
proxy.js:
var proxy = require('redbird')({port: 80});
proxy.register("myfirstapp.com", "http://localhost:3000");
proxy.register("mysecondapp.com", "http://localhost:4000");
然后 运行:
sudo node proxy.js
请注意,meteor 应用程序是 运行来自捆绑包还是仍在使用 meteor
并不重要。但当然前者更适合生产。
这就是我想要完成的……我正在尝试在我的开发机器上使用 nginx 设置一个反向代理服务器,并在不同的本地端口上本地托管三个流星应用程序。我希望我的 nginx 根据虚拟目录重定向请求...像 localhost/App1 会重定向到 localhost:3010 而 localhost/App2 会重定向到 localhost:3011。这些应用程序将需要使用 Meteor Identity 微服务(第三个应用程序)进行身份验证,并且这些应用程序将需要使用 localhost/Iden 之类的东西来重定向未经身份验证的用户
作为第一步,我有这个设置: 我正在尝试在本地 Nginx 上部署 app1 Meteor 应用程序。我已经使用 "meteor build" 构建了应用程序并将内容移动到我的根目录所在的 Nginx/html。通过 nginx 端口 (localhost:81) 浏览应用程序后,我无法加载任何流星包,但能够加载应用程序文件。该应用程序本身是 运行 localhost:3000
错误如下
Error screenshot : Chrome console
我可以单独浏览我创建的资源文件,例如 todo.js
localhost:81/app/template.todo1.js?979b20f66caf126704c250fbd29ce253c6cb490e
但我无法浏览到 meteor 包文件
localhost:81/packages/global-imports.js?af67437fd606dadafb22ec5e8bfc6ca8314a60ad
因为它 returns 404
下面是我的 nginx 配置
#user nginx;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 0.0.0.0:81;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~* "^/[a-z0-9]{60}\.(css|js)$" {
root /app1/bundle/programs/server;
access_log off;
expires max;
}
location ~ "^/packages" {
root /app1/bundle/programs/server;
access_log off;
}
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /app1/bundle/programs/server;
access_log off;
expires max;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
#proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
location /app2 {
proxy_pass http://127.0.0.1:3010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
#proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
感谢任何帮助,因为我从昨天开始就在努力解决这个问题
如果您只需要反向代理,那么我建议使用 redbird:
npm install redbird
然后,例如,如果您有两个 meteor 应用 运行在本地端口 3000 和 4000 上:
proxy.js:
var proxy = require('redbird')({port: 80});
proxy.register("myfirstapp.com", "http://localhost:3000");
proxy.register("mysecondapp.com", "http://localhost:4000");
然后 运行:
sudo node proxy.js
请注意,meteor 应用程序是 运行来自捆绑包还是仍在使用 meteor
并不重要。但当然前者更适合生产。