VPS侦探论坛

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

重定向导致的奇怪错误

[复制链接]
发表于 2016-3-18 12:24:58 | 显示全部楼层 |阅读模式

请军哥帮忙看看!LNMP1.3安装完,添加虚拟主机,工作正常,IP访问或未添加的地址都指向LNMP那个默认页面。
需要把某个二级域名转发到81端口上的另一个服务,因此在/usr/local/nginx/conf/vhost下添加一个conf文件,内容为:
server
{

listen 80;

server_name test.xxx.com;

rewrite ^(.*) http://test.xxx.com:81/$1 permanent;
}

重启LNMP之后,包括这个二级域名、以前配置了别的虚拟主机的域名或者IP,所有的都无法访问,ERR_CONNECTION_REFUSED。
删除这个配置文件,重启LNMP,依旧。
用lnmp vhost add添加一个test.xxx.com,依旧。
自此所有对这台主机80端口的访问全部ERR_CONNECTION_REFUSED。
这是为什么呢?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-3-18 12:35:28 | 显示全部楼层


如果用 scheme 來轉呢?

[ 本帖最后由 scorpioliu 于 2016-3-18 12:36 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2016-3-18 12:52:51 | 显示全部楼层

/usr/local/nginx/sbin/nginx -t 测试配置
netstat -ntl 查看端口
iptables -L -n 确认规则
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2016-3-18 13:24:01 | 显示全部楼层



正常时是这样

/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:54399           0.0.0.0:*               LISTEN
tcp6       0      0 :::51907                :::*                    LISTEN
tcp6       0      0 :::3306                 :::*                    LISTEN
tcp6       0      0 :::111                  :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::25                   :::*                    LISTEN

iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0            icmptype 8

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

异常时这样:
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:54399           0.0.0.0:*               LISTEN
tcp6       0      0 :::51907                :::*                    LISTEN
tcp6       0      0 :::3306                 :::*                    LISTEN
tcp6       0      0 :::111                  :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::25                   :::*                    LISTEN


iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0            icmptype 8

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
异常时少一行
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
80端口上没有监听
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2016-3-18 13:27:30 | 显示全部楼层

发现lnmp restart时,出现一个错误:
Stoping nginx... nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
但是查看这个"/usr/local/nginx/logs/nginx.pid"文件为空

[ 本帖最后由 zorange 于 2016-3-18 13:46 编辑 ]

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

 楼主| 发表于 2016-3-18 13:34:08 | 显示全部楼层

发现reboot后,80上的服务正常了,但是设置了转发的test.xxx.com并没有被转发到81。
lnmp restart后,80上再次没有服务。
再次重启,报错
Stoping LNMP...
Stoping nginx... nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
failed. Use force-quit
[ ok ] Stopping mariadb (via systemctl): mariadb.service.
Gracefully shutting down php-fpm . done
Starting LNMP...
Starting nginx... nginx (pid 3568 3567 3469) already running.
[ ok ] Starting mariadb (via systemctl): mariadb.service.
Starting php-fpm  done
 楼主| 发表于 2016-3-18 13:49:08 | 显示全部楼层

我发现问题的根本原因了,不是端口转发的问题,是重启lnmp时nginx没起来。
Starting nginx... nginx (pid 3568 3567 3469) already running.
我81端口上跑的也是个nginx,这个重启时发现已有一个,就没启动。
但为什么reboot后就能同时启两个呢?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2016-3-18 14:26:05 | 显示全部楼层

好吧,我为什么非要跑两个nginx呢,用一个吧……
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-29 01:30 , Processed in 0.027697 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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