情况描述
$ sudo service nginx reload
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ sudo service nginx status
nginx.service - A high performance web server and a reverse proxy server
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
....
解决办法
根据报错,可以知道是因为两个服务器的默认端口都是80,产生冲突
法一:关掉Apache
暂停Apache服务 或者 杀掉某pid的进程
网上该类解法的博文很多,不赘述
法二:换Nginx的默认端口
① /etc/nginx/nginx.conf
笔者未在该文件夹中直接找到localhost 80
的相关设置,找到了一段相关设置
②根据上图,找到 /etc/nginx/sites-enabled
文件夹
文件夹中都有default
文件,打开后出现localhost 80
的相关设置
将80端口改为新的端口即可,两个文件都完成相同的操作
$ sudo service nginx restart
打开新的端口 出现了令人快乐的初始页面!
注
修改完端口后,如果直接敲命令查看状态,还是会报80端口不可用的错,记得先重启服务器!