Created
August 1, 2012 13:19
-
-
Save ryu-blacknd/3226800 to your computer and use it in GitHub Desktop.
Nginx+Apacheでリバースプロキシ構築時の設定例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# キャッシュ関連設定 | |
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=czone:4m max_size=50m inactive=120m; | |
proxy_temp_path /var/tmp/nginx; | |
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; | |
# バックエンドサーバ-(Apache)設定 | |
upstream backend { | |
ip_hash; | |
server 127.0.0.1:8080; | |
} | |
# | |
# The default server | |
# | |
server { | |
listen 80; | |
server_name _; | |
root /var/www/html; | |
# /wp-admin 以下はバックエンドサーバ- | |
location /wp-admin { | |
proxy_pass http://backend; | |
} | |
# .php ファイルはバックエンドサーバ- | |
location ~ .*\.php { | |
proxy_pass http://backend; | |
} | |
# .ht(xxx) ファイルはアクセス禁止 | |
location ~ /\.ht { | |
deny all; | |
} | |
# 静的ファイルはアクセスログに記録せず、30日間キャッシュする | |
location ~ .*\.(txt|xml|html?|js|css|gz|ico|jpe?g|gif|png|wmv|flv|swf|mpg) { | |
access_log off; | |
expires 30d; | |
break; | |
} | |
# それ以外のファイルは | |
# ・フィーチャーフォン/スマートフォンでキャシュ先を変更 | |
# ・ログイン済みユーザーの場合はキャッシュOFF | |
# としたうえで、バックエンドサーバ- | |
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://backend; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment