在nginx中配置gzip比较简单
一般情况下只要在nginx.conf的http段中加入下面几行配置即可
gzip on; gzip_min_length 1000; gzip_buffers 48k; gzip_types text/plain application/x-javascript text/css text/html application/xml;
可以通过网页gzip检测工具来检测网页是否启用了gzip
临时重定向示例:访问www.lansgg.com/c 重定向到www.lansgg.com/cc
编辑nginx.conf
server {
listen 80 default_server;
server_name www.lansgg.com lansgg.com;
access_log logs/lansgg.access.log main;
error_log logs/lansgg.error.log;
root /opt/nginx/nginx/html/lansgg;
index index.html;
rewrite ^/c/(.*)$ http://www.lansgg.com/cc/$1;
}
[root@master lansgg]# tree
.
├── c
│ └── index.html
├── cc
│ └── index.html
├── index.html
└── it.jpg
2 directories, 4 files
访问http://www.lansgg.com/c 会跳转到http://www.lansgg.com/cc

302即为临时重定向;
永久重定向(隐含重定向)
编辑nginx.conf
server {
listen 80 default_server;
server_name www.lansgg.com lansgg.com;
access_log logs/lansgg.access.log main;
error_log logs/lansgg.error.log;
root /opt/nginx/nginx/html/lansgg;
index index.html;
rewrite ^/c/(.*)$ /cc/$1;
}
访问 http://www.lansgg.com/c/ 页面显示的是跳转后的页面,可是url却没有变化;firebug也看不到302代码信息;现在它其实是301;
2、反向代理:是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个服务器。
2.1、配置nginx实现反向代理;
需求:访问http://192.168.10.128/other 返回 apache主机的other目录下的Index.html

涉及nginx指令:
语法:proxy_pass URL
可使用字段:location, location中的if字段
这个指令设置被代理服务器的地址和被映射的URI,地址可以使用主机名或IP加端口号的形式,例如:proxy_pass http://192.168.10.129/url
2.2、配置nginx配置文件nginx.conf
server {
listen 80 default_server;
server_name www.lansgg.com lansgg.com;
access_log logs/lansgg.access.log main;
error_log logs/lansgg.error.log;
root /opt/nginx/nginx/html/lansgg;
location / {
index index.html;
}
location /other {
proxy_pass http://192.168.10.129/other;
proxy_set_header X-Real-IP $remote_addr;
}
}








