Nginx笔记
1. Nginx 反向代理的设置
server {
listen 80;
server_name api.zhaisoft.com;
index index.html index.htm index.php;
root /alidata/www/api.zhaisoft.com;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix: /tmp/php-cgi.sock;fastcgi_pass 127.0.0.1: 9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}port_in_redirect off;
location /api {
rewrite ^/api(.*)$ $1 break;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:8081;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}gzip on;
gzip_min_length 1k; #低于1kb的资源不压缩
gzip_comp_level 3; #压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片,下面会讲为什么。
gzip_disable “MSIE [1-6]\.”; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
gzip_vary on; #是否添加“Vary: Accept-Encoding”响应头error_log /var/log/nginx/error_blog.log error;
client_max_body_size 50m;
#access_log /alidata/log/nginx/access/1314.foreverlove.log;}