Skip to content

Instantly share code, notes, and snippets.

@arganzheng
Last active December 20, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arganzheng/6128961 to your computer and use it in GitHub Desktop.
Save arganzheng/6128961 to your computer and use it in GitHub Desktop.
我本地的nginx.conf,配合proxifier可以做灰度测试。
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
# use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#在日志格式中加入$upstream_cache_status
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'"$upstream_cache_status" $request_time';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server_names_hash_bucket_size 64;
# Have nginx do the compression.
gzip on;
gzip_comp_level 1;
gzip_disable msie6;
gzip_proxied any;
# text/html mime type is automatically included for gzip, have to add the rest
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml text/javascript;
## Begin Proxy Cache Config
#keys_zone=cache1:100m 表示这个zone名称为cache1,分配的内存大小为100MB
#/usr/local/nginx/proxy_cache_dir/cache1 表示cache1这个zone的文件要存放的目录
#levels=1:2 表示缓存目录的第一级目录是1个字符,第二级目录是2个字符,即/usr/local/nginx/proxy_cache_dir/cache1/a/1b这种形式
#inactive=1d 表示这个zone中的缓存文件如果在1天内都没有被访问,那么文件会被cache manager进程删除掉
#max_size=10g 表示这个zone的硬盘容量为10GB
proxy_cache_path data/proxy_cache_dir/nantianmen levels=1:2 keys_zone=nantianmen:100m inactive=1d max_size=2g;
proxy_temp_path data/proxy_temp_dir 1 2;
#设置缓存的key
# Putting the host name in the cache key allows different virtual hosts to share the same cache zone
proxy_cache_key "$scheme://$host$request_uri";
# Pass some client identification headers back to the backend_server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
upstream backend_server {
server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=30s;
}
# Cache different return codes for different lengths of time
# We cached normal pages for 10 minutes
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
# Virtual host definition
server {
listen 80;
server_name mbrowser.baidu.com;
#$upstream_cache_status表示资源缓存的状态,有HIT MISS EXPIRED UPDATING STALE BYPASS几种状态
add_header X-Nginx-Cache $upstream_cache_status;
location ~ /cache {
#设置资源缓存的zone
proxy_cache nantianmen;
# If it's not in the cache pass back to the backend-server
proxy_pass http://backend_server;
}
#
# Proxy all remaining content to the backend-server
#
location / {
proxy_pass http://backend_server;
}
}
#配置Purge
location ~ /purge(/.*) {
#允许的IP
allow 127.0.0.1;
#10网段的都可以访问
allow 192.168.10.0/24;
deny all; #其他的禁止访问
proxy_cache_purge cache1 $scheme://$host$request_uri;
}
}
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
## HTTPS server
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
server {
listen 80;
server_name victor.qq.com weikeduo.qq.com wkd.qq.com;
client_max_body_size 10M;
if ( $host = victor.qq.com ) {
rewrite ^/(.*)$ http://wkd.qq.com/$1 break;
}
if ( $host = weikeduo.qq.com ) {
rewrite ^/(.*)$ http://wkd.qq.com/$1 break;
}
location ~ ^/mobile {
proxy_pass http://10.149.21.223:9011;
}
location ~ ^/buyer {
proxy_pass http://10.149.21.223:9010;
}
location ~ /portal {
proxy_pass http://10.6.206.48:8582;
}
location / {
# proxy_pass http://127.0.0.1:8080;
# proxy_pass http://10.191.135.16:9006;
proxy_pass http://10.191.134.158:9006;
}
}
server {
listen 80;
server_name fuwu.paipai.com;
client_max_body_size 10M;
location / {
# proxy_pass http://127.0.0.1:8080;
#proxy_pass http://172.23.1.122:9008;
#proxy_pass http://10.137.141.85:9008;
#proxy_pass http://10.130.129.205:9008;
proxy_pass http://172.27.28.177:9008;
}
}
server {
listen 80;
server_name api.paipai.com;
client_max_body_size 10M;
location / {
#proxy_pass http://172.23.1.122:9001;
proxy_pass http://10.130.129.205:9001;
}
}
server {
listen 80;
server_name api.yixun.com apitest.yixun.com;
client_max_body_size 10M;
location / {
proxy_pass http://10.6.223.106:9008;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment