Mac下安裝nginx
準(zhǔn)備
如果沒有安裝homebrew像街,需要先執(zhí)行以下命令安裝们拙。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝
在終端命令中輸入:
brew install nginx
等待安裝完成外遇。
/usr/local/var/www #默認(rèn)網(wǎng)站路徑
/usr/local/etc/nginx/nginx.conf #默認(rèn)配置文件蔬墩,默認(rèn)端口8080斤贰,修改此配置文件的listen改為80端口
/usr/local/etc/nginx/servers/ #默認(rèn)加載配置文件夾
/usr/local/Cellar/nginx/1.8.1 #默認(rèn)安裝路徑
開機啟動
注意:~/Library/Library可能需要創(chuàng)建
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
如果上面開機啟動命令不對篡帕,可以 brew info nginx
查看信息
設(shè)置權(quán)限:
sudo chown root:wheel /usr/local/Cellar/nginx/1.8.1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.8.1/bin/nginx
重新加載配置|重啟|停止|退出 nginx
nginx -s reload|reopen|stop|quit
測試配置是否有語法錯誤
nginx -t
更多詳細 nginx 幫助信息:
nginx -h
我本地的一個配置信息(/usr/local/etc/nginx/nginx.conf)
server {
listen 80;
server_name test.com;
root html/test/public;
location / {
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php$ {
send_timeout 60;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}