【发布时间】:2015-07-02 07:45:07
【问题描述】:
我通过 home brew 安装 nginx,当我尝试启动或停止它时,我收到以下错误
➜ ~ sudo nginx -s stop
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
➜ ~ sudo nginx
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] still could not bind()
文件结构
➜ ~ /usr/local/var/run
➜ run git:(master) ls
nginx
➜ run git:(master) cd nginx
➜ nginx git:(master) ls
client_body_temp fastcgi_temp proxy_temp scgi_temp uwsgi_temp
➜ nginx git:(master)
检查 nginx 是否正在运行
➜ ~ ps waux | grep nginx
harshamv 963 0.0 0.0 2432772 656 s000 S+ 1:32PM 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=.cvs --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx
当我尝试运行 Nginx 时,出现以下错误。
➜ ~ nginx
nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)
2015/07/02 13:39:44 [emerg] 1074#0: open() "/usr/local/var/log/nginx/access.log" failed (13: Permission denied)
【问题讨论】:
-
它不会启动,因为 8080 端口正在使用中(由某个进程打开,可能是 nginx,但看起来不像)。
pgrep nginx会告诉你 nginx 是否还在运行,lsof -i 4tcp |grep 8080会告诉你如果不是 nginx,哪个进程正在持有 8080 端口。 -
@LeonidShevtsov 是的 nginx 正在端口 8080 上运行,我该如何阻止它?
-
当我运行这些命令时,没有显示任何内容@LeonidShevtsov
-
请运行
sudo netstat -lnt | grep :8080。如果输出为空,则说明 8080 端口没有任何内容。您是否运行了上面建议的lsof命令?如果 nginx 正在运行,您可以将其杀死,因为缺少 pid 文件,因此启动/停止脚本将无法停止它。 -
当我转到 localhost:8080 时,我会看到欢迎来到 Nginx 屏幕。当我运行
sudo netstat -lnt | grep :8080和lsof -i 4tcp |grep 8080时,它只是回到提示行。