Skip to content

Instantly share code, notes, and snippets.

@cantremember
Created March 23, 2012 05:56
Show Gist options
  • Save cantremember/2167455 to your computer and use it in GitHub Desktop.
Save cantremember/2167455 to your computer and use it in GitHub Desktop.
nginx vhost example
server {
include extra/proxy.conf;
include mime.types;
listen 80;
server_name blog.DOMAIN.NAME;
access_log logs/LOGFILE-access.log;
###error_log logs/LOGFILE-error.log debug;
error_log logs/LOGFILE-error.log;
# Settings | General | WordPress address (URL)
location /WP-CONTEXT {
# physical location on server
root /PATH/TO/WP-DIR;
index index.php index.html index.htm;
# remove virtual path, make it root-relative
rewrite ^/WP-CONTEXT(.*)$ $1;
# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}
# addresses '/wp-admin/' and similar vein
if (-f $request_filename/index.php) {
# produces '...//index.php', acceptable loss
rewrite ^(.+)$ /WP-CONTEXT$1/index.php last;
}
# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /WP-CONTEXT/index.php?q=$1 last;
}
}
location ~ \.php$ {
# remove virtual path, make it root-relative
rewrite ^/WP-CONTEXT(.*)$ $1;
fastcgi_pass fastcgi_cluster;
fastcgi_index index.php;
# physical location on server
fastcgi_param SCRIPT_FILENAME /PATH/TO/WP-DIR$fastcgi_script_name;
include fastcgi_params;
}
# Settings | General | Blog address (URL)
location / {
# WordPress handles this perfectly as-is
fastcgi_pass fastcgi_cluster;
# physical location on server
fastcgi_param SCRIPT_FILENAME /PATH/TO/WP-DIR/index.php;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment