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
先要安装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代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- web 应用中常用的各种 cache详解
- Linux系统上配置Nginx+Ruby on Rails+MySQL超攻略
- window+nginx+php环境配置 附配置搭配说明
- asp.net URL重写简化版 速学URL重写
- linux下apache开启url重写的方法(详细说明)
- 解析CI即CodeIgniter框架在Nginx下的重写规则
- 将PHP从5.3.28升级到5.3.29时Nginx出现502错误