實驗環境:centos7.2,已安裝httpd,80端口被佔用。nginx
編輯httpd配置文件:apache
# vim /etc/httpd/conf/httpd.conf
找到Listen,修改httpd監聽端口:vim
重啓apache服務:centos
# systemctl restart httpd.service
安裝nginx:bash
# yum -y install nginx
nginx安裝成功,驗證配置文件及端口:服務器
# nginx -t
若是安裝完成之後80端口被佔用了,即便怎麼中止佔用80端口的應用,甚至刪除應用,nginx -t都會提示 nginx: [emerg] socket() [::]:80 failed (97: Address family not supported bysocket
解決辦法是修改配置文件:(# vim /etc/nginx/conf.d/default.conf)ide
listen 80 default_server; listen [::]:80 default_server;
改爲:測試
listen 80 default_server; #listen [::]:80 default_server;
設置開機自動啓動:centos7
# systemctl enable nginx.service
啓動nginx服務器&查看nginx當前狀態:
域名測試:
公網ip測試: