【发布时间】:2016-04-27 02:27:43
【问题描述】:
所以,我现在真的很难过。我有两个 nodejs 应用程序。一个在 8080 端口上运行,一个在 8081 上运行。它们都在相同的 IP 地址上运行。我有两个域,domain1.com 和 domain2.com。我使用 Nginx 作为反向代理,将 domain1.com 重定向到端口 8080,将 domain2.com 重定向到端口 8081。我目前的问题是 domain1.com 是唯一可行的。我只能通过 domain1.com:8081 或 domain2.com:8081 访问其他节点应用程序。
domain1.com.conf:
server {
listen 80;
server_name domain1.com www.domain1.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
domain2.com.conf:
server {
listen 80;
server_name domain1.com www.domain1.com;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
nginx.conf:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
任何帮助将不胜感激。我绞尽脑汁想了这么久,在网上找不到很多相关的答案。 顺便说一句,我在 CentOS 6.3 上运行所有这些
更新:在排除更多故障后。我发现我的问题可能不是 nginx 问题,因为我完全关闭了 nginx 服务并且我的节点应用程序仍在显示。这很奇怪,因为端口 80 上没有运行任何东西。我什至使用 netstat 命令检查端口 80 上是否有任何东西在运行。我现在很困惑。如果有人对如何解决此问题或如何进一步排除故障有任何想法。请告诉我。
【问题讨论】:
-
为什么
server_name中有两个域? -
正如 Alexey 所说,您在 domain2.conf 中有错字。使用
server_name domain2.com www.domain2.com;而不是server_name domain1.com www.domain2.com; -
是我的错字,在实际的配置文件中不是这样
标签: node.js nginx reverse-proxy