您的位置:首页 > 运维架构 > Nginx

nginx url重写

2016-02-15 17:56 387 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx url重写