ユーザ用ツール

サイト用ツール


Sidebar

ミドルウェア系:nginx:nginx_1.4:リバースプロキシ設定

リバースプロキシ設定

だいたいこんな感じ。

  • Wordpressの場合
proxy_cache_path  /var/cache/nginx_new levels=1:2 keys_zone=czone:4m max_size=50m inactive=120m;
proxy_temp_path   /var/tmp/nginx_new;
proxy_cache_key   "$scheme://$host$request_uri";
proxy_set_header  Host               $host;
proxy_set_header  X-Real-IP          $remote_addr;
proxy_set_header  X-Forwarded-Host   $host;
proxy_set_header  X-Forwarded-Server $host;
proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
 
upstream blog_backend {
    ip_hash;
    server 127.0.0.1:8080;
}
 
server {
    listen       80;
    server_name  blog.matsumoto-r.jp;
    root         /usr/local/apache/htdocs/blog;
 
    location /wp-admin {
        proxy_pass http://blog_backend;
    }
 
    location ~ .*\.php {
        proxy_pass http://blog_backend;
    }
 
    location ~ /\.ht {
        deny  all;
    }
 
    location ~ .*\.(txt|xml|html?|js|css|gz|ico|jpe?g|gif|png|wmv|flv|swf|mpg) {
        #access_log  off;
        expires 30d;
        break;
    }
 
    location / {
        set $mobile "";
        if ($http_user_agent ~* '(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter)') {
            set $mobile "@ktai";
        }
        if ($http_user_agent ~* '(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry)') {
            set $mobile "@mobile";
        }
        if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
            set $do_not_cache 1;
        }
        proxy_no_cache     $do_not_cache;
        proxy_cache_bypass $do_not_cache;
        proxy_cache czone;
        proxy_cache_key "$scheme://$host$request_uri$is_args$args$mobile";
        proxy_cache_valid  200 301 302 10m;
        proxy_cache_valid  404 5m;
        proxy_pass http://blog_backend;
    }
 
}
ミドルウェア系/nginx/nginx_1.4/リバースプロキシ設定.txt · 最終更新: 2013/04/28 22:04 by matsumoto_r