in mac https://www.cnblogs.com/meng1314-shuai/p/8335140.htmljavascript
mac下啓動:html
經過brew 安裝install 後
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plistjava
查看安裝位置:linux
ps -ef | grep nginxnginx
啓動服務:cookie
sudo nginxapp
中止服務:ide
sudo nginx -s stopui
語法檢查:spa
sudo nginx -t
重載配置不停服:
sudo nginx -s reload
經常使用關鍵詞:rewrite、proxy_pass
location ^~ /address/ { proxy_set_header Host xx.sohu.com; #設置header proxy_set_header Origin http://xx.sohu.com; #proxy_set_header Cookie "$http_cookie; coder=lxf"; #通常cookie會自動轉發,此處能夠追加cookie #proxy_pass http://192.168.1.1:8888/; # hostNow/address/a 轉發至 hostOther/a,等效於下面兩行,正則的時候不能加/ rewrite /address/(.+)$ /$1 break; #正則匹配 proxy_pass http://192.168.1.1:8888; } location ~ (getList|search|folders) { #正則匹配 proxy_set_header Host free-mail-backend-test.sce.sohuno.com; proxy_set_header Origin http://free-mail-backend-test.sce.sohuno.com; proxy_pass http://free-mail-backend-test.sce.sohuno.com; }
其餘:
Nginx中不容許if嵌套;
不能設置邏輯運算符(好比啊A&&B),實現邏輯運算只能經過累加計數器或者寫到正則裏,以下:
location / { alias /opt/src/app/; expires 24h; set $myindex index.html; #MSIE 6-7 且 XP或Vista系統 才認爲是IE6-7 if ($http_user_agent ~* "MSIE [6-7]\.\d.+Windows NT (5\.|6\.0)") { set $myindex browserGuide.html; } index $myindex; }
參考:
http://www.cnblogs.com/AloneSword/p/3673829.htmlhttp://linux.it.net.cn/e/server/nginx/2014/0709/2704.html