gpt4 book ai didi

node.js - Nginx 反向代理不适用于域名

转载 作者:搜寻专家 更新时间:2023-11-01 00:47:42 24 4
gpt4 key购买 nike

我已经在 SO 上尝试了所有的解决方案,但没有成功。我想使用 Nginx 作为“Node.js”应用程序反向代理。使用我当前的配置,我能够在通过服务器 IP 连接到它时使它工作,但在使用其域名时不能。我的配置详细信息 pastebin.com/gMqpmDwj

http://Ipaddress:3000 有效,但 http://example.com 无效。

这是我的 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;
}
}

但是当我尝试访问它时,它在 ip:port 上工作正常,但在 domain:port 上或没有 port 时它不

最佳答案

试试这个配置:

/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

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;
}
}

关于node.js - Nginx 反向代理不适用于域名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57116932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com