Skip to content

Instantly share code, notes, and snippets.

@mintindeed
Created June 21, 2012 20:12
Show Gist options
  • Save mintindeed/2968252 to your computer and use it in GitHub Desktop.
Save mintindeed/2968252 to your computer and use it in GitHub Desktop.
WordPress + nginx config
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_ignore_client_abort off;
fastcgi_intercept_errors on;
fastcgi_connect_timeout 120;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
# In our dev configs we have PHP + nginx + ssh running as the same user for simplicity
user my_nginx_user;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
# Enable access log
log_format main
'$request_time $upstream_response_time '
'$http_x_forwarded_for, '
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
# file location: /etc/nginx/sites-available/wordpress.conf
index index.php index.html index.htm;
server {
listen 80;
server_name wordpress.local;
# access_log /var/log/nginx/wordpress.local.access.log;
client_max_body_size 128M;
client_body_buffer_size 128k;
## Set the real IP.
proxy_set_header True-Client-IP $http_true_client_ip;
proxy_set_header X-Real-IP $remote_addr;
## Set the hostname
proxy_set_header Host $host;
## Set the forwarded-for header.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
## Default location
root /var/www/sites/wordpress/;
# Check if files/directory exist, if not rewrite to index.php
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ \.php$ {
gzip off;
fastcgi_pass phpfcgi;
include fastcgi_params;
}
## Images and static content is treated different
location ~* ^.+.(ico|jpg|png|css|js|gif|jpeg|swf|htm|html)$ {
# access_log off;
expires 30d;
}
## Don't log requests for favicon
location = /favicon.ico {
log_not_found off;
access_log off;
expires 30d;
}
## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
}
upstream phpfcgi {
server 127.0.0.1:9000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment