niginx相关命令及代理配置

安装

in mac https://www.cnblogs.com/meng1314-shuai/p/8335140.html

Nginx相关命令

mac下启动:

通过brew 安装install 后
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

查看安装位置:

ps -ef | grep nginx

启动服务:

sudo nginx

停止服务:

sudo nginx -s stop

语法检查:

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.html
http://linux.it.net.cn/e/server/nginx/2014/0709/2704.html

 

posted @ 2016-04-22 17:10  youryida  阅读(479)  评论(0编辑  收藏  举报