[英]Nginx reverse proxy not working on domain name
I have tried all the solution on SO but no success.我已经在 SO 上尝试了所有解决方案,但没有成功。 I want to use Nginx as a "Node.js" app reverse proxy.我想将 Nginx 用作“Node.js”应用程序反向代理。 With my current configurations, I was able to make it work when connecting to it through the server IP but not when using its domain name.My configuration details pastebin.com/gMqpmDwj使用我当前的配置,我能够在通过服务器 IP 连接到它时使其工作,但在使用其域名时却不能。我的配置详细信息pastebin.com/gMqpmDwj
http://Ipaddress:3000
works but http://example.com
doesn't. http://Ipaddress:3000
有效,但http://example.com
无效。
Here is the configuration of my Nginx proxy, stored in /etc/Nginx/conf.d/domain.conf
.这是我的 Nginx 代理的配置,存储在/etc/Nginx/conf.d/domain.conf
。
server {
listen 80;
server_name domain_name;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://ipaddress:3000;
}
}
But when I try to access it works fine on ip:port
but when on domain:port
or without port
it doesn't但是当我尝试访问它时,它在ip:port
上工作正常,但是在domain:port
或没有port
时却没有
Try this configuration:试试这个配置:
/etc/nginx/nginx.conf /etc/nginx/nginx.conf
user nobody;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
client_max_body_size 8M;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log /var/log/nginx/error.log crit;
gzip on;
gzip_min_length 100;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/cloudflare.inc;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/domain.conf /etc/nginx/conf.d/domain.conf
upstream nodejs_app {
server <ipaddress>:3000;
keepalive 8;
}
server {
listen 80;
listen [::]:80;
server_name <domain_name>;
location / {
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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://nodejs_app/;
proxy_redirect off;
}
}
I solved my issue after following this link.I had multiple configuration files active that was causing problem.跟随此链接后,我解决了我的问题。我有多个导致问题的配置文件处于活动状态。 How to Configure Nginx Reverse Proxy for Nodejs on Centos 如何在 Centos 上为 Nodejs 配置 Nginx 反向代理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.