VPS侦探论坛

 找回密码
 注册
查看: 5193|回复: 7

[Nginx] Nginx反向代理端口失败

[复制链接]
发表于 2021-2-18 16:37:59 | 显示全部楼层 |阅读模式

您好!
       尝试反向代理一个运行在 5212 端口的程序,配置如下:
  1. <blockquote>server
复制代码

另:打开域名显示Nignx默认页面(如下图),nginx以及被反代的程序都已经重启过,执行/usr/local/nginx/sbin/nginx -t 测试配置文件未报错,请求解答,谢谢!

美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2021-2-18 16:39:03 | 显示全部楼层


以下是配置
  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name mingyueqingfeng.pp.ua mingyueqingfeng.pp.ua;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/mingyueqingfeng.pp.ua;

  8.         include rewrite/other.conf;
  9.         #error_page   404   /404.html;

  10.         # Deny access to PHP files in specific directory
  11.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  12.         include enable-php-pathinfo.conf;

  13. location ~ / {
  14.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  15.     proxy_set_header Host mingyueqingfeng.pp.ua;
  16.     proxy_redirect off;
  17.     proxy_pass http://127.0.0.1:5212;
  18.    
  19.     # 如果您要使用本地存储策略,请将下一行注释符删除,并更改大小为理论最大文件尺寸
  20.     # client_max_body_size 20000m;
  21.    }

  22.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  23.         {
  24.             expires      30d;
  25.         }

  26.         location ~ .*\.(js|css)?$
  27.         {
  28.             expires      12h;
  29.         }

  30.         location ~ /.well-known {
  31.             allow all;
  32.         }

  33.         location ~ /\.
  34.         {
  35.             deny all;
  36.         }

  37.         access_log  /home/wwwlogs/mingyueqingfeng.pp.ua.log;
  38.     }
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2021-2-18 20:19:37 | 显示全部楼层

/usr/local/nginx/conf/example/nginx-reverse-proxy-example.conf 有反向代理的配置文件,按例子配置就行
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2021-2-20 20:53:15 | 显示全部楼层



licess 发表于 2021-2-18 20:19
/usr/local/nginx/conf/example/nginx-reverse-proxy-example.conf 有反向代理的配置文件,按例子配置就行 ...

按例子配置仍然无效
  1. server {
  2.         listen 80;
  3.         #listen [::]:80;
  4.         server_name mingyuelou.tk;

  5.         #如果需要http 301跳转到 https 需要将下面行前面的 # 注释去掉,并重载nginx
  6.         #return 301 https://$host$request_uri;

  7.         location / {
  8.             proxy_pass http://127.0.0.1:5212;
  9.             proxy_http_version    1.1;
  10.             proxy_cache_bypass    $http_upgrade;
  11.             proxy_set_header Upgrade            $http_upgrade;
  12.             proxy_set_header Connection         "upgrade";
  13.             proxy_set_header Host               $host;
  14.             proxy_set_header X-Real-IP          $remote_addr;
  15.             proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
  16.             proxy_set_header X-Forwarded-Proto  $scheme;
  17.             proxy_set_header X-Forwarded-Host   $host;
  18.             proxy_set_header X-Forwarded-Port   $server_port;
  19.         }

  20.         access_log off;
  21. }

  22. server {
  23.         listen 443 ssl http2;
  24.         #listen [::]:443 ssl http2;
  25.         server_name mingyuelou.tk;

  26.         ssl_certificate /usr/local/nginx/conf/ssl/mingyuelou.tk.crt;
  27.         ssl_certificate_key /usr/local/nginx/conf/ssl/mingyuelou.tk.key;
  28.         ssl_session_timeout 5m;
  29.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  30.         ssl_prefer_server_ciphers on;
  31.         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";
  32.         ssl_session_cache builtin:1000 shared:SSL:10m;
  33.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  34.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  35.         location / {
  36.             proxy_pass http://127.0.0.1:5212;
  37.             proxy_http_version    1.1;
  38.             proxy_cache_bypass    $http_upgrade;
  39.             proxy_set_header Upgrade            $http_upgrade;
  40.             proxy_set_header Connection         "upgrade";
  41.             proxy_set_header Host               $host;
  42.             proxy_set_header X-Real-IP          $remote_addr;
  43.             proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
  44.             proxy_set_header X-Forwarded-Proto  $scheme;
  45.             proxy_set_header X-Forwarded-Host   $host;
  46.             proxy_set_header X-Forwarded-Port   $server_port;
  47.         }

  48.         access_log off;
  49. }
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2021-2-21 11:19:01 | 显示全部楼层

Abx 发表于 2021-2-20 20:53
按例子配置仍然无效

nginx -t 是否报错
nginx是否重启
访问返回什么信息?

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2021-2-21 12:14:35 | 显示全部楼层

licess 发表于 2021-2-21 11:19
nginx -t 是否报错
nginx是否重启
访问返回什么信息?
  1. root@srv9516:~# nginx -t
  2. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  3. nginx: configuration file /etc/nginx/nginx.conf test is successful
  4. root@srv9516:~# nginx -s reload
  5. root@srv9516:~#
复制代码

访问返回403,加端口才能正常显示程序页面
发表于 2021-2-21 19:47:40 | 显示全部楼层

Abx 发表于 2021-2-21 12:14
访问返回403,加端口才能正常显示程序页面

服务器上分别执行:
curl -IL http://127.0.0.1:5212
curl -IL http://你反代域名 看一下
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2021-2-28 13:59:54 | 显示全部楼层

Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-8 09:07 , Processed in 0.027819 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表