网上找了一篇相关的文章,http://bbs.vpser.net/thread-11786-1-1.html,可对我的问题无解,继续查。
关键提供Lnmp的Lnmp.org网站,不知道为何无法访问了,苦B了。
[root@excel nginx]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 68:f7:28:b4:88:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.40.4/24 brd 192.168.40.255 scope global enp4s0
valid_lft forever preferred_lft forever
inet6 fe80::6af7:28ff:feb4:8810/64 scope link
valid_lft forever preferred_lft forever
[root@excel nginx]# lnmp status
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| http://lnmp.org |
+-------------------------------------------+
nginx (pid 2592 2591 2590) is running...
php-fpm is runing!
SUCCESS! MySQL running (2970)
[root@excel nginx]# netstat -tanp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2970/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2590/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1031/sshd
tcp 0 248 192.168.40.4:22 192.168.40.14:14934 ESTABLISHED 2496/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 1031/sshd
[root@excel nginx]# firewall-cmd --state
running
[root@excel nginx]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@excel nginx]#
[root@excel nginx]# wget http://192.168.40.4/index.html
--2015-06-17 17:44:30-- http://192.168.40.4/index.html
Connecting to 192.168.40.4:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2285 (2.2K) [text/html]
Saving to: ?.ndex.html?
100%[================================================================================>] 2,285 --.-K/s in 0s
2015-06-17 17:44:30 (276 MB/s) - ?.ndex.html?.saved [2285/2285]
[root@excel nginx]# ls
client_body_temp conf fastcgi_temp html index.html logs proxy_temp sbin scgi_temp uwsgi_temp
通过Wget试到本机的WEB服务是正常的,仅是非本机连接就无法访问,可能还是80端口被阻拦。
网上找到关闭防火墙命令试下:
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
再次访问WEB服务,正常工作了。
原来Centos 7,发现无法使用iptables控制Linuxs的端口,而使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload
文中本是已增加了80端口只是没有进行重启,经过一次停用和启用,防火墙的设置生效。
详细信息可以参考以下资料:
http://stackoverflow.com/questions/24729024/centos-7-open-firewall-port
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html