实验环境:centos7.2,已安装httpd,80端口被占用。


编辑httpd配置文件:

# vim /etc/httpd/conf/httpd.conf


找到Listen,修改httpd监听端口:

wKioL1jhE-KTyoaaAAAyN08U2Vw830.png

重启apache服务:

# systemctl restart httpd.service


安装nginx:

# yum -y install nginx


nginx安装成功,验证配置文件及端口:

# nginx -t

wKiom1jhFofRHGIrAAAWuOwxvs4883.png


如果安装完成以后80端口被占用了,即使怎么停止占用80端口的应用,甚至删除应用,nginx -t都会提示 nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by

解决办法是修改配置文件:(# vim /etc/nginx/conf.d/default.conf)

listen       80 default_server;
listen       [::]:80 default_server;

改成:

listen       80 default_server;
#listen       [::]:80 default_server;


设置开机自动启动:

# systemctl enable nginx.service

wKiom1jhGIbyDcWGAAAW4IMB6Iw056.png


启动nginx服务器&查看nginx当前状态:

wKioL1jhGIbjpJm0AACr9_IgQTs147.png


域名测试:

wKiom1jhGkHQBWqkAAC9P2NUEwM586.png


公网ip测试:

wKioL1jhG0ngDv3IAAB7Pk35HXM684.png