Using nginx + wordpress with all wordpress files in a subdirectory
Posted
by
GorillaPatch
on Server Fault
See other posts from Server Fault
or by GorillaPatch
Published on 2010-12-11T09:29:27Z
Indexed on
2011/02/18
7:27 UTC
Read the original article
Hit count: 755
My setup
I am running nginx 0.7.67 on Debian Lenny as a webserver, not as a reverse proxy. I am using php5-fpm to handle my PHP requests, which works fine.
My aim
I would like to have a wordpress installation that is layed out as described here clean wordpress subversion installation. I would like to have a clean wordpress installation without cluttering my server root directory with all the wordpress files.
That means that my wordpress installation would be in /wordpress
and my themes and plugins inside /wordpress-content
.
The important point however is that if you navigate to my domain www.example.com then you would be taken directly to the wordpress blog, without having to specify the subdirectory where wordpress lives.
I found a how-to at the nginx site installing wordpress but unfortunately this is for moving the entire wordpress directory instead of redirecting the traffic to it.
I tried with the following configuration:
example.conf in sites-available
server {
listen 80;
server_name www.example.com;
access_log /var/log/nginx/www.example.com.access.log main;
root /var/www/example/htdocs;
location / {
try_files $uri $uri/ /wordpress/index.php?q=$uri&$args;
}
include /etc/nginx/includes/php5-wordpress.conf;
include /etc/nginx/includes/deny.conf;
}
php5-wordpress.conf in includes
location /wordpress {
try_files $uri $uri/ /wordpress/index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/wordpress)(/.*)$;
fastcgi_ignore_client_abort on;
fastcgi_pass unix:/var/run/php5-fpm.socket;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
fastcgi_params
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
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 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;
The problems I have is that when I go to the adress "http://www.example.com" I get a 403 error as I disabled directory listing. Instead I would like my wordpress to appear then. Also if I navigate to "http://www.example.com/wordpress" I get a "file not found" error. However if I comment out the fastcgi_split_path_info line in my php5-wordpress.conf at least the wordpress installation works inside /wordpress.
I need help how to debug this behavior or where I can find more information.
Thanks alot.
Update: Added error log entry for the 403 error.
in the error.log I get the following entry for the 403 error:
2010/12/11 07:54:24 [error] 9496#0: *1 directory index of
"/var/www/example/htdocs/" is forbidden, client: XXX.XXX.XXX.XXX,
server: www.example.com, request: "GET / HTTP/1.1", host: "www.example.com"
Update 2: Added the nginx.conf below:
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
index index.php index.html;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
© Server Fault or respective owner