Created
October 14, 2011 08:44
-
-
Save miya0001/1286587 to your computer and use it in GitHub Desktop.
nginx+リバースプロキシでバーチャルホスト
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
# | |
# A virtual host using WordPress | |
# /etc/nginx/conf.d/example.com.conf | |
# | |
server | |
{ | |
listen 8080; | |
client_max_body_size 10m; | |
server_name .example.com; | |
set $vhost_root "/home/example.com"; | |
root $vhost_root; | |
index index.php index.html index.htm; | |
location / { | |
if (-f $request_filename) | |
{ | |
expires 14d; | |
break; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(.+)$ /index.php?q=$1 last; | |
} | |
} | |
location ~ \.php$ { | |
include /etc/nginx/fastcgi_params; | |
fastcgi_pass unix:/tmp/php-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $vhost_root/$fastcgi_script_name; | |
fastcgi_pass_header "X-Accel-Redirect"; | |
fastcgi_pass_header "X-Accel-Buffering"; | |
fastcgi_pass_header "X-Accel-Charset"; | |
fastcgi_pass_header "X-Accel-Expires"; | |
fastcgi_pass_header "X-Accel-Limit-Rate"; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
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
####################################################################### | |
# | |
# This is the main Nginx configuration file. | |
# | |
# More information about the configuration options is available on | |
# * the English wiki - http://wiki.nginx.org/Main | |
# * the Russian documentation - http://sysoev.ru/nginx/ | |
# | |
####################################################################### | |
#---------------------------------------------------------------------- | |
# Main Module - directives that cover basic functionality | |
# | |
# http://wiki.nginx.org/NginxHttpMainModule | |
# | |
#---------------------------------------------------------------------- | |
user www; | |
worker_processes 2; | |
error_log /var/log/nginx/error.log; | |
#error_log /var/log/nginx/error.log notice; | |
#error_log /var/log/nginx/error.log info; | |
pid /var/run/nginx.pid; | |
#---------------------------------------------------------------------- | |
# Events Module | |
# | |
# http://wiki.nginx.org/NginxHttpEventsModule | |
# | |
#---------------------------------------------------------------------- | |
events { | |
worker_connections 1024; | |
} | |
#---------------------------------------------------------------------- | |
# HTTP Core Module | |
# | |
# http://wiki.nginx.org/NginxHttpCoreModule | |
# | |
#---------------------------------------------------------------------- | |
http { | |
server_tokens off; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
access_log off; | |
sendfile on; | |
keepalive_timeout 5; | |
#gzip on; | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_vary on; | |
gzip_comp_level 6; | |
gzip_types text/xml text/css application/xhtml+xml application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php; | |
gzip_disable "MSIE [1-6]\."; | |
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=czone:4m max_size=50m inactive=30d; | |
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; | |
# | |
# The default server | |
# | |
upstream backend { | |
server 127.0.0.1:8080; | |
} | |
server | |
{ | |
listen 80 default_server; | |
server_name _; | |
client_max_body_size 10M; | |
location /wp-admin { proxy_pass http://backend; } | |
location ~ .*\.php { proxy_pass http://backend; } | |
location / { | |
if ($http_cookie ~* "wordpress_(?!test_cookie)") { | |
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"; | |
proxy_cache_valid 0; | |
proxy_pass http://backend; | |
} | |
} | |
server { | |
listen 8080 default_server; | |
server_name _; | |
return 444; | |
} | |
# Load config files from the /etc/nginx/conf.d directory | |
include /etc/nginx/conf.d/*.conf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wp専用のバーチャルホスト。
example.com.confをコピーしてserver_nameと$vhost_rootを変更する。
あとはDNSを向けるだけ。