Nginx没有开始,自制软件说它是

yoo*_*uri 3 macos homebrew nginx

brew服务说nginx已经启动..

MacBook-Pro-van-Youri:Homebrew youri$ brew services start nginx
Service `nginx` already started, use `brew services restart nginx` to restart.
Run Code Online (Sandbox Code Playgroud)

与launchctl相同

MacBook-Pro-van-Youri:Homebrew youri$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist 
/Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist: service already loaded
Run Code Online (Sandbox Code Playgroud)

我的homebrew.mxcl.nginx.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.nginx</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/nginx/bin/nginx</string>
        <string>-g</string>
        <string>daemon off;</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/usr/local</string>
  </dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

酿酒服务清单说明如下:

MacBook-Pro-van-Youri:LaunchAgents youri$ brew services list
Name    Status  User  Plist
mariadb started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
nginx   error   youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist
php71   started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.php71.plist
Run Code Online (Sandbox Code Playgroud)

语法是oke:

MacBook-Pro-van-Youri:LaunchAgents youri$ plutil -lint homebrew.mxcl.nginx.plist 
homebrew.mxcl.nginx.plist: OK
Run Code Online (Sandbox Code Playgroud)

当我运行时,sudo nginx我可以访问我的网站

yoo*_*uri 13

因为nginx将从端口80开始,所以它必须是root.

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Run Code Online (Sandbox Code Playgroud)

移动homebrew.mxcl.nginx.plist

sudo mv ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
Run Code Online (Sandbox Code Playgroud)

从LaunchDaemons文件夹加载plist

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
Run Code Online (Sandbox Code Playgroud)

现在,sudo brew services list显示一个正在运行的nginx进程

Name    Status  User  Plist
nginx   started root  /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
Run Code Online (Sandbox Code Playgroud)

brew services list没有root的情况下运行会导致错误状态,因为您需要root才能读取状态

  • 第三个命令给出“路径的所有权/权限错误” (7认同)
  • 对我来说,只有“launchctl unload/load”有效,而“launchctl start/stop”无法启动任何 Nginx 进程。 (2认同)
  • @AkshaySoam 然后更改文件的所有权: `/Library/LaunchDaemons/homebrew.mxcl.nginx.plist` 与目录中的其他文件相同: `sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx .plist` (2认同)