Take the 2-minute tour ×

I have had quite a time trying to get nginx to serve static assets from my wordpress blog. Have a look at the config and let me know if you can help. ( https://gist.github.com/1130332 - to see the entire thing)

server {

listen  80;
server_name  subprint.com;
access_log /var/www/subprint/logs/access.log;
error_log /var/www/subprint/logs/error.log;

root   /var/www/subprint/server/public; # express serves static resources for subprint.com out of here

location / {
  root   /var/www/subprint/server;
  access_log on;

#serve static assets
location ~* ^(?!\/).+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
    expires max;
    access_log off;

# the route for the wordpress blog
# unfortunately the static assets (css, img, etc.) are not being pathed/served properly
location /blog {

    root /var/www/localhost/public;
    index index.php;
    access_log /var/www/localhost/logs/access.log;
  error_log /var/www/localhost/logs/error.log;

  if (!-e $request_filename) {

    if (!-f $request_filename) {
      rewrite /blog$ /blog/index.php last;


# actually serves the wordpress and subsequently phpmyadmin
location ~* (?!\/blog).+\.php$ {
 fastcgi_pass   localhost:9000;  
 fastcgi_index  index.php;
 fastcgi_param  SCRIPT_FILENAME    /var/www/localhost/public$fastcgi_script_name;  
 fastcgi_param PATH_INFO               $fastcgi_script_name;
 include /usr/local/nginx/conf/fastcgi_params;

# This works fine, but ONLY with a symlink inside the /var/www/localhost/public directory pointing to /usr/share/phpmyadmin
location /phpmyadmin {
    index index.php;
    access_log /var/www/phpmyadmin/logs/access.log;
    error_log /var/www/phpmyadmin/logs/error.log;
    alias /usr/share/phpmyadmin/;

    if (!-f $request_filename) {
      rewrite /phpmyadmin$ /phpmyadmin/index.php permanent;
# opt-in to the future
add_header "X-UA-Compatible" "IE=Edge,chrome=1";


share|improve this question

1 Answer 1

There's a whole wiki page dedicated to wordpress: http://wiki.nginx.org/Wordpress

As for phpMyAdmin. The reason you need a symlink is because you have different roots for the two. Nginx only ever applies one location block to a request, so you can set an alias or root in location /phpmyadmin but as soon as you rewrite it to /phpmyadmin/index.php the locations are re-evaluated and a new location is applied (thus the alias/root in location /phpmyadmin has no effect)

share|improve this answer
Thanks Martin, but how does that resolve wordpress serving up the actual pages, but not the static content? –  joemccann Aug 7 '11 at 12:57
Also, I read the wiki Wordpress page ages ago and unfortunately it does not cover my issue at all. –  joemccann Aug 7 '11 at 12:58
Finally, if I do remove the alias in the /phpmyadmin then I get 404s, so it is required. –  joemccann Aug 7 '11 at 13:00
If you read the page then why aren't you following any of the advice? There's no if (!-f $request_filename) { on that page. You cannot remove the alias, that wasn't my point, my point was that if you want to avoid symlinking then you need a location for PHP to handle the phpmyadmin file so you can specify the correct root there. –  Martin Fjordvald Aug 7 '11 at 22:14
PHPMyAdmin is NOT the problem; wordpress. I am unable to serve the static contents from the Wordpress directory, not PHPMyAdmin –  joemccann Aug 12 '11 at 11:02

Your Answer


