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