Nginx反向代理端口失败
您好!尝试反向代理一个运行在 5212 端口的程序,配置如下:
<blockquote>server
另:打开域名显示Nignx默认页面(如下图),nginx以及被反代的程序都已经重启过,执行/usr/local/nginx/sbin/nginx -t 测试配置文件未报错,请求解答,谢谢!https://ae01.alicdn.com/kf/Ub013a32770774feeb25531fea8650cfeJ.jpg
https://imgchr.com/i/yWZQw4
以下是配置
server
{
listen 80;
#listen [::]:80;
server_name mingyueqingfeng.pp.ua mingyueqingfeng.pp.ua;
index index.html index.htm index.php default.html default.htm default.php;
root/home/wwwroot/mingyueqingfeng.pp.ua;
include rewrite/other.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo.conf;
location ~ / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host mingyueqingfeng.pp.ua;
proxy_redirect off;
proxy_pass http://127.0.0.1:5212;
# 如果您要使用本地存储策略,请将下一行注释符删除,并更改大小为理论最大文件尺寸
# client_max_body_size 20000m;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log/home/wwwlogs/mingyueqingfeng.pp.ua.log;
}
/usr/local/nginx/conf/example/nginx-reverse-proxy-example.conf 有反向代理的配置文件,按例子配置就行 licess 发表于 2021-2-18 20:19
/usr/local/nginx/conf/example/nginx-reverse-proxy-example.conf 有反向代理的配置文件,按例子配置就行 ...
按例子配置仍然无效
server {
listen 80;
#listen [::]:80;
server_name mingyuelou.tk;
#如果需要http 301跳转到 https 需要将下面行前面的 # 注释去掉,并重载nginx
#return 301 https://$host$request_uri;
location / {
proxy_pass http://127.0.0.1:5212;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto$scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
access_log off;
}
server {
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name mingyuelou.tk;
ssl_certificate /usr/local/nginx/conf/ssl/mingyuelou.tk.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/mingyuelou.tk.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
location / {
proxy_pass http://127.0.0.1:5212;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto$scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
access_log off;
}
Abx 发表于 2021-2-20 20:53
按例子配置仍然无效
nginx -t 是否报错
nginx是否重启
访问返回什么信息? licess 发表于 2021-2-21 11:19
nginx -t 是否报错
nginx是否重启
访问返回什么信息?
root@srv9516:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@srv9516:~# nginx -s reload
root@srv9516:~#
访问返回403,加端口才能正常显示程序页面 Abx 发表于 2021-2-21 12:14
访问返回403,加端口才能正常显示程序页面
服务器上分别执行:
curl -IL http://127.0.0.1:5212
curl -IL http://你反代域名 看一下 https://s3.ax1x.com/2021/02/28/69fyKx.png
页:
[1]