Nginx没有启动,Homebrew说它是

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

brew services says nginx is started..

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

字符串
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


我的自制软件.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>


brew services list说:

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


语法是oke:

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


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

hfsqlsce

hfsqlsce1#

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

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

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

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


从LaunchDaemons文件夹加载plist

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


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

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


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

zf9nrax1

zf9nrax12#

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

sudo brew services start nginx

字符串

相关问题