nginx url重写

nginx的安装,
先要安装pcre,zlib,openssl这两个软件。
下载并解压nginx-1.6.3。 这里的版本很重要,因为我当时使用1.8的版本来试用,可是怎么测试都没办法URL头部重写,也去官网看了说是稳定版本了,最后面就下降版本就OK了。
进行nginx的目录中。
再安装nginx
安装命令:
第一步./configure --prefix=要安装的地址(如:/usr/common/nginx)
--wih-http_stub_status_module。
第二步:make,make install.

安装完成后:
下载nginx.conf文件到本地进行修改。
修改内容如下:
upstream cctest1.com{
        server  192.168.0.171:7011;    
    }
    #图片指定的地址,要创建/usr/common/cache的目录,目录可以变化
    proxy_cache_path /usr/common/cache/cachelevels=1:2 keys_zone=imgcache:1m inactive=2h max_size=100g
   server {
        listen       80;
        server_name  cctest1.com;
        #这里的正测表达式请注意:因为REST的get有两种请求方式。  
        location ~* ^/(.*?)/(.*?)/(.*?)/(.*?)/([^/?]*)(.*?)$ {            
            proxy_pass http://cctest1.com/$1/$2/$3$6?$args;
            proxy_http_version 1.1;
            proxy_method POST;
            proxy_set_header Connection "";    
            proxy_set_header User-Agent CollaGEN3;
            proxy_set_header Accept "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            proxy_set_header Accept-Language  "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
            proxy_set_header Accept-Encoding  deflate;
            proxy_set_header COLLAGEN-REQUESTER_ID $4;
            proxy_set_header COLLAGEN-AUTHORIZE_ID $5;
            proxy_set_header COLLAGEN-PROXY_FLOW_ID $1::01::FLOW_C3_CALL_RESTFUL_PROXY;
            proxy_set_header COLLAGEN-SESSION_ID 1;
            proxy_set_header COLLAGEN-TIMEOUT  10S;
            proxy_set_header COLLAGEN-DEBUG  ON;
            proxy_set_header COLLAGEN-OUT_PARAMETERS _ALL_;
            log_not_found off;
            access_log off;
            expires 7d;
            proxy_cache imgcache;
            proxy_cache_valid 200 1d;
            proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
        }
    }
进行到你刚才指定的地址中的conf,输入rz -y 把本地修改好的nginx.conf上传。

再进入cd ../sbin,启动nginx.
检查命令:./nginx -t 先检查nginx.conf是否正常。
启动命令:./nginx
停止命令:./nginx -s stop
重启命令:./nginx -s reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值