【问题标题】:OSX - Start and Stopping of Nginx errorOSX - Nginx 错误的启动和停止
【发布时间】: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 :8080lsof -i 4tcp |grep 8080 时,它只是回到提示行。

标签: macos nginx homebrew


【解决方案1】:

我遇到过一个案例。如果你用一个看起来像nginx -c my.conf的conf文件启动nginx,你必须用nginx -s stop -c my.conf停止它。

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

我认为当您遇到此类错误时,您可以选择检查ps -ef | grep nginx 的 pid,至少可以手动杀死它。

【讨论】:

    【解决方案2】:

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

    解决:

    sudo chown -R 用户名运行

    chmod -R 777 运行/

    如果有其他权限问题

    喜欢“xxx”权限,请使用“chown”“chmod”命令。

    这样我的问题就解决了!

    【讨论】:

    • 这是一个非常糟糕的建议。 chmod 777 永远不是正确的解决方案。
    • 是的,你是对的。但在我的个人电脑 chmod 777 中,它只是用于测试。在服务器端,可以设置严格权限。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 2016-12-19
    相关资源
    最近更新 更多