centOS7訪問nginx失敗解決-.0:80 failed (98: Address already in use)解決

前提:已經配置好靜態IP
以防萬一,先安裝好iptables服務(不管你裝沒裝,先執行,免得後面添亂)
[root@localhost ~]# yum install iptables-services
[root@localhost ~]# systemctl mask firewalld.service
[root@localhost ~]# systemctl enable iptables.service
[root@localhost ~]# systemctl enable ip6tables.service
進入iptables配置80端口,因爲nginx默認是由80端口訪問
[root@localhost ~]# vim /etc/sysconfig/iptables
這是配置信息:

Generated by iptables-save v1.4.21 on Fri May 12 21:28:29 2017

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6:696]
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 21 -j ACCEPT(我給vsftpd配置的端口)
-A INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT(給nginx配置的端口,原樣輸入就行了)
-A INPUT -p tcp -m state –state NEW -m tcp –dport 30000:30999 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT

Completed on Fri May 12 21:28:29 2017

然後:wq,保存退出就行了
重啓iptables,配置才生效
[root@localhost ~]# systemctl restart iptables.service
開啓防火牆,不管你開沒有,再開一遍:
[root@localhost ~]# systemctl start firewalld
開啓http訪問
[root@localhost ~]# firewall-cmd –permanent –add-service=http
加入80端口
[root@localhost ~]# firewall-cmd –permanent –zone=trusted –add-port=80/tcp
啓動nginx!!!!(重點來了!!!)
centOS7的nginx啓動與其他的有區別!!!注意:我是裝的nginx1.80,在centOS6.X系列中,是通過

cd /usr/local/nginx/sbin/

./nginx
這兩條命令啓動的。
在Ubuntu中是通過/etc/nginx…..,你會發現你的centOS7裏面,etc下面根本就沒有nginx這個folder!
在centOS7中你會發現這行不通,我們應該這麼啓動:
[root@localhost ~]# /usr/local/nginx/sbin/nginx
如果發現:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
說明80端口被佔用,殺掉這個進程:
[root@localhost ~]# killall -9 nginx
再次啓動nginx:
[root@localhost ~]# /usr/local/nginx/sbin/nginx
查看是否啓動:
[root@localhost ~]# ps aux|grep nginx
輸出:
root 7110 0.0 0.0 24348 752 ? Ss 22:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 7111 0.0 0.0 26860 1508 ? S 22:32 0:00 nginx: worker process
root 7114 0.0 0.0 112664 968 pts/0 S+ 22:33 0:00 grep –color=auto nginx
啓動成功!
訪問nginx
在瀏覽器地址欄輸入你的Linux虛擬機的靜態ip,會跳轉到nginx的歡迎頁面。
原文鏈接:原文鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章