Create a gist now

Instantly share code, notes, and snippets.

@yiwa /default.conf
Last active Aug 29, 2015

What would you like to do?
nginxでリバースプロキシを設定する時のnginx/conf.d/default.conf
upstream backend {
server 127.0.0.1:8080;
}
server {
listen 8080;
server_name _;
root /var/www/html;
index index.html index.htm index.php;
charset utf-8;
gzip off;
gzip_vary off;
location / {
index index.php index.html index.htm;
# static files
if (-f $request_filename) {
access_log off;
break;
}
# request to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# Default server
server {
listen 80;
server_name _;
root /var/www/html;
index index.html index.htm index.php;
charset utf-8;
#access_log logs/host.access.log main;
fastcgi_read_timeout 120;
#
# set mobile
#
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|Windows Phone)') {
set $mobile ".smartphone";
}
#
# set cache and expire date
#
location ~ .*\.(txt|xml|html?|js|css|gz|ico|jpe?g|gif|png|wmv|flv|mpg|woff) {
access_log off;
expires 30d;
break;
}
#
# do not use cache at wp-admin
#
location /wp-admin {
proxy_pass http://backend;
}
#
# set do_not_cache
#
location / {
set $do_not_cache 0;
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_key "$scheme://$host$request_uri$is_args$args$mobile";
proxy_cache_valid 200 10m;
proxy_cache_valid 404 5m;
proxy_pass http://backend;
}
#
# redirect server error pages to the static page
#
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment