如何在OS X上重启nginx

clw*_*wen 52 macos restart nginx

nginx在OS X 10.8上使用.新安装nginx但无法找到重启nginx的方法除外kill nginx_pidkill 64116.想知道是否有更好的方法重新启动nginx.

在Google和SO上找到了一些方法,但没有奏效:

nginx -s restart

sudo fuser -k 80/tcp ; sudo /etc/init.d/nginx restart
Run Code Online (Sandbox Code Playgroud)

错误消息nginx -s restart

nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
Run Code Online (Sandbox Code Playgroud)

有时也会得到这个错误消息:

nginx: invalid option: "-s restart"
Run Code Online (Sandbox Code Playgroud)

Ben*_*ier 96

sudo nginx在启动nginx之前尝试运行.

  • 这不适合我.与OP相同的错误. (6认同)

Mah*_*dsi 19

你的nginx pid文件位置是什么?这在配置文件中指定,在配置脚本中指定编译时的默认路径.你可以这样搜索它:

find / -name nginx.pid 2>/dev/null (必须在nginx运行时发出)

解:

sudo mkdir -p /usr/local/var/run/
ln -s /current/path/to/pid/file /usr/local/var/run/nginx.pid
Run Code Online (Sandbox Code Playgroud)

  • 似乎更好的模拟重启的方法是`nginx -s stop; nginx` (12认同)
  • 或者``nginx -s reload`如果你只需要更新配置 (8认同)
  • 那是因为它不是一个有效的信号.检查`man`页面(无论如何你都应该这样做):`向主进程发送信号:停止,退出,重新打开,重新加载. (7认同)

tob*_*bek 19

要重新加载配置文件:

sudo nginx -s reload
Run Code Online (Sandbox Code Playgroud)

要完全重启nginx:

sudo nginx -s quit
sudo nginx
Run Code Online (Sandbox Code Playgroud)

细节

restartnginx 没有信号.从文档中,以下是主进程接受的信号:

SIGINT, SIGTERM  Shut down quickly.
SIGHUP           Reload configuration, start the new worker process with a new configuration, and gracefully shut down old worker processes.
SIGQUIT          Shut down gracefully.
SIGUSR1          Reopen log files.
SIGUSR2          Upgrade the nginx executable on the fly.
SIGWINCH         Shut down worker processes gracefully.
Run Code Online (Sandbox Code Playgroud)

据推测,您可以手动将这些信号发送到进程ID,但该nginx命令具有nginx -s <signal>向您的主进程发送信号的标志.你的选择是:

stop    SIGTERM
quit    SIGQUIT
reopen  SIGUSR1
reload  SIGHUP
Run Code Online (Sandbox Code Playgroud)

手动无需使用pid.


编辑:刚刚意识到这些信息已经在其他答案的评论中.无论如何离开这里总结一下情况.

  • 我得到这个sudo nginx -s reload nginx:[error] open()"/ usr/local/var/run/nginx.pid"失败(2:没有这样的文件或目录) (2认同)

小智 8

$ sudo nginx -c /usr/local/etc/nginx/nginx.conf
$ sudo nginx -s reload
Run Code Online (Sandbox Code Playgroud)

源码链接:https : //blog.csdn.net/github_33644920/article/details/51733436


Blu*_*ari 6

我是这样做的:

首先杀死进度

ps aux | grep nginx
kill -9 {pid}
Run Code Online (Sandbox Code Playgroud)

然后启动nginx

nginx
Run Code Online (Sandbox Code Playgroud)

有用!


Bri*_*nos 6

尝试这个:

sudo nginx -s stop

后跟一个:

sudo nginx

nginx 似乎会跟踪它的状态,如果你停止它两次,它会抱怨。但以上对我有用。