Configuration help needed

Ian Hobson ian at ianhobson.co.uk
Fri Jul 31 18:05:45 MSD 2009


Hi all,

I'm using nginx version 0.5.33   (I know its old - its the standard on 
Ubuntu).

I have a site that works fine - *.htm pages are served via a shared 
script (builder), static pages with nginx, *.php directly via PHP, and a 
little tweak because we were finding half our bandwidth was going to 
people showing our pictures in their pages!

Now to add a  wordpress blog to /blog/.

Below is one of my many attempts.  The old stuff still works, and  
/blog/readme.html and its images are served properly as static content.
However....
    /blog    is passed to builder not /blog/index.php  (log status 200)
    /blog/index.php  is also passed to builder.     (log status 302)

This is the config file in /etc/nginx/sites-available 
#  emc.titan.hcs     - internal test server
server {
   listen   80;
    server_name emc.titan.hcs;
    root   /home/ian/websites/emccatering;
    fastcgi_index index.htm;
   location = /images/ {
        return 403;
   }
    location /blog {
       ## do rewrites for wordpress (which sets location to 
/blog/index.php)
       if (-f $request_filename) {
            # serve static content
           break;
        }
        # rewrite  /blog/<page> as  /blog/index.php?q=<page>
        rewrite ^/blog/(.+)$ /blog/index.php?q=/blog/$1 last;
        #  Enable nice permalinks for WP
        error_page 404 = /blog/index.php?q=$uri;
    }
   location /blog/index.php {
       # send wordpress commands to php /blog/index.php?q=page 
       fastcgi_param  SCRIPT_FILENAME 
/home/ian/websites/emccatering/blog/index.php;
        fastcgi_param  QUERY_STRING    $request_uri;
        fastcgi_param  DOCUMENT_ROOT   $document_root;
        fastcgi_pass  127.0.0.1:9000;
    }
    location  ~ ^(.*)/$ {
       # matches directories
        fastcgi_param  QUERY_STRING       f=${request_uri}index.htm;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SCRIPT_FILENAME    
/home/ian/websites/builder/parser.php;
        fastcgi_pass  127.0.0.1:9000;
    }
   # pass file names to php
    location ~ \.htm$ {
        # send .htm files to builder as  /builder/parser.php?f=page.htm 
- NB builder is shared
        fastcgi_pass  127.0.0.1:9000;       
        fastcgi_param  QUERY_STRING       f=$request_uri;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SCRIPT_FILENAME    
/home/ian/websites/builder/parser.php;
    }
    # handle vanilla php files as well - neither WP nor builder
    location ~ \.php {
         fastcgi_pass  127.0.0.1:9000;
        include /etc/nginx/fastcgi_params;
    }
    location /images/ {
        #  stop leaches stealling bandwidth for food pics!
        valid_referers none emc.titan.hcs;
        if ($invalid_referer) {
            return 403;
        }
    }       
}

Thanks for  your help.

Ian








More information about the nginx mailing list