Skip to content

Instantly share code, notes, and snippets.

@gordjw
Created June 4, 2015 12:21
Show Gist options
  • Save gordjw/eedcdbf3e556aa729f35 to your computer and use it in GitHub Desktop.
Save gordjw/eedcdbf3e556aa729f35 to your computer and use it in GitHub Desktop.
Nginx config file to serve wordpress core and wp-content from different directories
server {
listen 443 ssl;
listen 80;
root /data/www/web/core;
server_name web;
server_name_in_redirect off;
client_max_body_size 100m;
index index.php index.html index.htm;
ssl_certificate /data/ssl/server.crt;
ssl_certificate_key /data/ssl/server.key;
#ssl_client_certificate /data/certs/cybertrust_intermediate_ca.cert;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# if X-Forwarded-Proto or X-Forwarded-Scheme are not HTTPS, redirect back to HTTPS
if ( $http_x_forwarded_scheme != 'https' ) {
#rewrite ^(.*)$ https://$host$request_uri? permanent;
}
gzip on;
gzip_comp_level 9;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
# Serve attachments
rewrite /files/$ /index.php last;
if ($uri !~ wp-content/plugins) {
rewrite /files/(.+)$ /index.php?file=$1 last;
}
location / {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
if (!-e $request_filename ) {
rewrite ^(/wp-login) /wp-login.php last;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
#rewrite ^(.+)$ /index.php?q=$1 last;
}
location ~ /\.ht {
deny all;
}
location ~* ^/wp-content/uploads/.*.php$ {
deny all;
}
location ~* /files/(.*).php$ {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ^~ /wp-content/ {
alias /data/www/web/wp-content/;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment