Macos OSX-启动和停止Nginx错误

Macos OSX-启动和停止Nginx错误,macos,nginx,homebrew,Macos,Nginx,Homebrew,我通过自制软件安装了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:

我通过自制软件安装了
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)

Mac OS X EI在/usr中没有权限

解决:

sudo chown-R用户名运行

chmod-R777运行/

如果有任何其他许可问题

像“xxx”权限一样,请使用“chown”“chmod”命令


这样我的问题就解决了

我遇到过一个案例。如果使用conf文件启动nginx,它看起来像
nginx-cmy.conf
,则必须使用
nginx-stop-cmy.conf
停止它

my.conf
文件中,可以使用
pid/some\u location/nginx.pid,这将在该位置生成一个pid文件,它不再是
/usr/local/var/run/nginx.pid
的默认位置,这就是您无法停止它的原因


我认为当您遇到这样的错误时,您可以选择检查
ps-ef | grep nginx
的pid,至少可以手动终止它。

它不会启动,因为8080端口正在使用中(由某些进程打开,可能是nginx,但看起来不像它)
pgrep nginx
将告诉您nginx是否仍在运行,并且
lsof-i 4tcp | grep 8080
将告诉您,如果8080端口不是nginx,那么哪个进程正在占用该端口。@LeonidShevtsov是的nginx正在8080端口上运行。我如何停止它?当我运行这些命令时,@LeonidShevtsov没有显示任何内容,请运行
sudo netstat-lnt | grep:8080
。如果输出为空,则没有任何内容保留端口8080。您是否运行了上面建议的
lsof
命令?如果nginx正在运行,您可以终止它,因为缺少pid文件,因此启动/停止脚本将无法停止它。当我转到localhost:8080时,我会看到欢迎使用nginx屏幕。当我运行
sudonetstat-lnt | grep:8080
lsof-i4tcp | grep8080
时,它只会返回提示行。这是非常糟糕的建议
chmod777
从来都不是正确的解决方案。是的,你是对的。但在我的个人电脑chmod777中,它只是用于测试。在服务器端,您可以设置严格的权限。