Nginx没有启动,Homebrew说它是

5kgi1eie  于 2023-11-17  发布在  Nginx
关注(0)|答案(2)|浏览(206)

brew services says nginx is started..

  1. MacBook-Pro-van-Youri:Homebrew youri$ brew services start nginx
  2. Service `nginx` already started, use `brew services restart nginx` to restart.

字符串
launchctl也是如此

  1. MacBook-Pro-van-Youri:Homebrew youri$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
  2. /Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist: service already loaded


我的自制软件.mxcl.nginx.plist

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3. <plist version="1.0">
  4. <dict>
  5. <key>Label</key>
  6. <string>homebrew.mxcl.nginx</string>
  7. <key>RunAtLoad</key>
  8. <true/>
  9. <key>KeepAlive</key>
  10. <false/>
  11. <key>ProgramArguments</key>
  12. <array>
  13. <string>/usr/local/opt/nginx/bin/nginx</string>
  14. <string>-g</string>
  15. <string>daemon off;</string>
  16. </array>
  17. <key>WorkingDirectory</key>
  18. <string>/usr/local</string>
  19. </dict>
  20. </plist>


brew services list说:

  1. MacBook-Pro-van-Youri:LaunchAgents youri$ brew services list
  2. Name Status User Plist
  3. mariadb started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
  4. nginx error youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist
  5. php71 started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.php71.plist


语法是oke:

  1. MacBook-Pro-van-Youri:LaunchAgents youri$ plutil -lint homebrew.mxcl.nginx.plist
  2. homebrew.mxcl.nginx.plist: OK


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

hfsqlsce

hfsqlsce1#

由于nginx将在端口80启动,因此它需要root。当用户登录时,LaunchAgent以非root用户身份运行。LaunchDaemons在 Boot 时以root用户身份加载。

  1. launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

字符串
移动homebrew.mxcl.nginx.plist

  1. sudo mv ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/


从LaunchDaemons文件夹加载plist

  1. sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist


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

  1. Name Status User Plist
  2. nginx started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist


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

展开查看全部
zf9nrax1

zf9nrax12#

如上所述,发生这种情况是因为端口80是保留的,它需要由root分配。
更简单的方法是使用sudo运行brew services

  1. sudo brew services start nginx

字符串

相关问题