树莓派打开Nginx失败(端口被占用)
打开Nginx时显示以下错误
nginx.serviceJob for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
发现其实是80端口被占用了,输入
sudo lsof -i:80
出现
pi@raspberrypi:~ $ sudo lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 558 root 3u IPv6 16143 0t0 TCP *:http (LISTEN)
apache2 559 www-data 3u IPv6 16143 0t0 TCP *:http (LISTEN)
apache2 560 www-data 3u IPv6 16143 0t0 TCP *:http (LISTEN)
可以看到我的80端口是被apache2占用了,所以直接输入
sudo /etc/init.d/apache2 stop
接下来再启动Nginx
pi@raspberrypi:~ $ sudo /etc/init.d/nginx start
[ ok ] Starting nginx (via systemctl): nginx.service.
出现ok的标志便表示Nginx已经启动成功了。
你也可以用`sudo fuser -k 80 / tcp`来停止使用端口80的进程。