一. 卸載
- nginx -s stop 停止nginx進程
- which nginx 查看nginx所在目錄 刪除
- brew remove nginx
二. 重新安裝
brew install nginx
三. 常用命令
nginx services start //啟動NGINX
nginx -t //檢測nginx是否可以正常啟動
nginx -s reload //重啟nginx 一般是在操作nginx.conf之后 執行這個操作
nginx -s stop //停止nginx進程
ps aux | grep "nginx: worker process" 查看當前nginx的work user是誰。
四. 相關配置路徑 - nginx.conf => /usr/local/etc/nginx/nginx.conf
- nginx 文件夾 => /usr/local/bin/nginx
- error.log 報錯日志 => /usr/local/var/log/nginx/error.log
- nginx root根路徑 => /usr/local/var/www/
五. 報錯及解決方案 - "/usr/local/Cellar/nginx/1.17.8/logs/nginx.pid" failed (2: No such file or directory)?
解決辦法: 發現/usr/local/Cellar/nginx/1.17.8/logs 這個logs文件夾沒有,所以 cd /usr/local/Cellar/nginx/1.17.8/
mkdir logs && chmod 777 logs //新建logs文件夾 并賦予777 所有權限 - nginx: [error] invalid PID number "" in "/usr/local/Cellar/nginx/1.17.8/logs/nginx.pid"?
解決辦法 : sudo /usr/local/bin/nginx -c /usr/local/etc/nginx/nginx.conf
把nginx 文件夾-c 到conf所在目錄
-c 將文件解壓縮到其他目錄 -
總算 reload成功,運行 403 Forbidden ?
解決辦法: 查看錯誤日志
根據時間看當前錯誤
image.png
錯誤信息說沒有權限查看root: /,所以找到nginx.conf的root改成對應的nginx文件夾 /usr/local/var/www/, 問題解決。
本地的nginx終于運行起來了,emmm ,繼續往下操作,晴晴要努力哇