Are these rules ok?

Shri @ DevLib.Org shri at devlib.org
Thu Dec 25 18:02:46 MSK 2008


Igor,

Here's what I have and it seems to work. Not sure if its correct. Any 
comments?

Also, any ideas on how best to handle these rules?

RewriteRule ^jobs/category/(.+)$ /jobs/index.php?cat_name=$1 [NC,L]
RewriteRule ^jobs/job/(.+)$ /jobs/index.php?post_permalink=1&post_id=$1 
[NC,L]
RewriteRule ^jobs/profile/(.+)$ /jobs/index.php?show_emp=$1 [NC,L]
RewriteCond %{QUERY_STRING} .+
RewriteRule ^jobs/page(.+) /jobs/index.php?%{QUERY_STRING}&job_page_link=$1 
[NC,L]
RewriteRule ^jobs/page(.+) /jobs/index.php?job_page_link=$1 [NC,L]




        root /site/expat/oct08;

        index index.php index.html index.htm;

        location / {
        try_files      $uri  @wordpress;
        }

    location ~ \.php$ {
        try_files      $uri  @wordpress;

                set $script $uri;
                set $path_info "";

                if ($uri ~ "^(.+\.php)(/.+)") {
                        set $script $1;
                        set $path_info $2;
                }

       fastcgi_param  SCRIPT_FILENAME 
/site/expat/oct08$fastcgi_script_name;
            fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
            fastcgi_index  index.php;
            fastcgi_param  PATH_INFO    $path_info;
            include        fastcgi_params;
    }


    location @wordpress {

        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/index.php;
            fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
            fastcgi_index  index.php;
            fastcgi_param  PATH_INFO    $path_info;
            include        fastcgi_params;

    }

        location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
                access_log      off;
                expires         30d;
                break;
        }

        location ^~ /scripts/ {
              proxy_pass http://cgiserver;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location ^~ /resources/Detailed/ {
              proxy_pass http://cgiserver;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

    location /forum/ {

        # this is handled above as exact match
        rewrite ^/forum/getnew.html$ /forum/search.php?do=getnew last;

        rewrite ^/forum/getnew([0-9]+).html$ 
/forum/search.php?do=getnew&f=$1 last;

        rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ 
/forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;

        rewrite ^/forum/unanswered.html$ 
/forum/search.php?do=process&replyless=1&replylimit=0&dontcache=1 last;

        rewrite ^/forum/unanswered([0-9]+).html$ 
/forum/search.php?do=process&replyless=1&replylimit=0&dontcache=1&forumchoice=$1&childforums=1 
last;

        try_files      $uri  @vbulletin;
    }

    location ~ ^/forum/.+\.php$ {
        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/forum/vbseo.php;
        include        fastcgi_params;
    }
    location @vbulletin {
        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/forum/vbseo.php;
        include        fastcgi_params;
    }


        location /classifieds/ {
                try_files $uri @classifieds;
        }

        location @classifieds {

            fastcgi_param  SCRIPT_FILENAME 
/site/expat/oct08$fastcgi_script_name;
            fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
            fastcgi_index  index.php;
            fastcgi_param  PATH_INFO    $path_info;
            include        fastcgi_params;

        }

        location ~ /\.ht {
            deny  all;
        }



----- Original Message ----- 
From: "Igor Sysoev" <is at rambler-co.ru>
To: <nginx at sysoev.ru>
Sent: Thursday, December 25, 2008 3:50 PM
Subject: Re: Are these rules ok?


> On Thu, Dec 25, 2008 at 08:09:45AM +0800, shri at devlib.org wrote:
>
>> Igor,
>>
>> Thank you very much for taking the time to answer.
>>
>> The setup is as follows.
>>
>> / <-- Wordpress is installed and shows the main page and content
>> /forum/ <-- vBulletin
>> /classifieds/ <-- Photopost
>> /scripts/ <-- perl CGI scripts
>> /resources/ <-- files built by the Gossamer Links CGI package
>> /resources/Detailed/ <-- More files built by the CGI package
>>
>> I am using 0.7.24 which is the latest -devel branch I found in the 
>> Freebsd
>> ports.
>>
>> Should I try a newer one?
>
> You may use either 0.7.24 (but without handy try_files) or the newest 
> 0.7.30.
>
> You may start from Wordpress configuration, and temporarily passing
> other location to old servers. I think you do need to set up PATH_INFO.
>
>    location / {
>        try_files      $uri  @wordpress;
>    }
>
>    location ~ \.php$ {
>        try_files      $uri  @wordpress;
>
>        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>        fastcgi_param  SCRIPT_FILENAME 
> /site/expat/oct08$fastcgi_script_name;
>        include        fastcgi_params;
>    }
>
>    location @wordpress {
>        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/index.php;
>        include        fastcgi_params;
>    }
>
>    # passing to all servers
>
>    location ^~ /forum/
>        proxy_pass    ...;
>    }
>
>    location ^~ /classifieds/
>        proxy_pass    ...;
>    }
>
>    location ^~ /scripts/
>        proxy_pass    ...;
>    }
>
>    location ^~ /resources/
>        proxy_pass    ...;
>    }
>
> Then you may try to setup vBulletin configuration:
>
>    location = /forum/getnew.html {
>        rewrite ^/forum/getnew.html$ /forum/search.php?do=getnew last;
>
>        # or you may right now set FastCGI paramters and pass the request
>        # to FastCGI, but you should remove QUERY_STRING from 
> fastcgi_params0
>
>        #fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>        #fastcgi_param  SCRIPT_FILENAME 
> /site/expat/oct08/forum/search.php;
>        #fastcgi_param  QUERY_STRING     do=getnew;
>        #include        fastcgi_params0;
>    }
>
>    location /forum/ {
>
>        # this is handled above as exact match
>        #rewrite ^/forum/getnew.html$ /forum/search.php?do=getnew last;
>
>        rewrite ^/forum/getnew([0-9]+).html$
>                 /forum/search.php?do=getnew&f=$1 last;
>
>        rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$
>                 /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
>
>        rewrite ^/forum/unanswered.html$
> 
> /forum/search.php?do=process&replyless=1&replylimit=0&dontcache=1 last;
>        rewrite ^/forum/unanswered([0-9]+).html$
> 
> /forum/search.php?do=process&replyless=1&replylimit=0&dontcache=1&forumchoice=$1&childforums=1 
> last;
>
>        try_files      $uri  @vbulletin;
>    }
>
>    location ~ ^/forum/.+\.php$ {
>        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/forum/vbseo.php;
>        include        fastcgi_params;
>    }
>
>    location @vbulletin {
>        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/forum/vbseo.php;
>        include        fastcgi_params;
>    }
>
> It's probably time to implement location captures in nginx:
>
>    location ~ /forum/getnew([0-9]+).html {
>        fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>        fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08/forum/search.php;
>        fastcgi_param  QUERY_STRING     do=getnew&f=$1;
>        include        fastcgi_params0;
>    }
>
> I will do this after vacation.
>
>> Thanks once again for replying. Have fun on your vacation!
>>
>> Regards,
>> Shri
>>
>>
>> On Wed, 24 Dec 2008 20:05:48 +0300, Igor Sysoev <is at rambler-co.ru> wrote:
>> > On Wed, Dec 24, 2008 at 11:32:46PM +0800, Shri @ GeoExpat.Com wrote:
>> >
>> >> I'm trying to setup my first site, which uses wordpress, photopost
>> > classifieds, vbulletin and gossamer threads (CGI Perl based) software -
>> > along with some fairly simple posts.
>> >>
>> >> The site is being migrated from apache (frontend) + lightttpd (static)
>> > to a nginx + fastcgi. I'm focused on migrating the PHP part first, as 
>> > we
>> > can always proxy the CGI requests to Apache.
>> >>
>> >> My nginx.conf looks like this (based on various bits and pieces found 
>> >> on
>> > google and mailing lists).
>> >>
>> >> My questions are
>> >>
>> >> 1) Am I missing something obvious?
>> >> 2) Why cant I get the Wordpress 404 to work correctly?
>> >> 3) We need to exclude a couple of countries due to various illegal 
>> >> spam
>> > issues. Is this http://wiki.codemongers.com/NginxHttpGeoModule the best
>> way
>> > to do it?
>> >>
>> >> Thanks in advance from someone who is VERY new to Nginx.
>> >
>> > How do you separate wordpress, photopost classifieds, vbulletin, and
>> > gossamer
>> > on the site ? I see vbulletin's /forums, and some /scripts/
>> > and /resources/Detailed/ only.
>> >
>> > BTW, note that nginx does not support CGI.
>> >
>> > If you use 0.6.34, then it's better to apply patch
>> > http://sysoev.ru/nginx/patch.try_files.0.6.34
>> > and use new "try_files" directive.
>> > In 0.7.30 already has this functionality.
>> >
>> > Then you can handle Wordpress using following configuration:
>> >
>> >     location / {
>> >         try_files      $uri  @wordpress;
>> >     }
>> >
>> >     location ~ \.php$ {
>> >         try_files      $uri  @wordpress;
>> >
>> >         fastcgi_param  SCRIPT_FILENAME  /path/to$fastcgi_script_name;
>> >         ... other fastcgi_param
>> >     }
>> >
>> >     location @wordpress {
>> >         fastcgi_pass   ...;
>> >
>> >         fastcgi_param  SCRIPT_FILENAME  /path/to/index.php;
>> >         ... other fastcgi_param
>> >     }
>> >
>> > This is replacement of these Apache rules:
>> >
>> > #RewriteCond %{REQUEST_FILENAME} !-f
>> > #RewriteCond %{REQUEST_FILENAME} !-d
>> > #RewriteRule . /index.php [L]
>> >
>> >
>> >> ---------------------
>> >>     server {
>> >>
>> >>         listen  80;
>> >>         server_name domain.com www.domain.com;
>> >>
>> >>         root /site/domain/dec08;
>> >>
>> >> #RewriteCond %{REQUEST_FILENAME} !-f
>> >> #RewriteCond %{REQUEST_FILENAME} !-d
>> >> #RewriteRule . /index.php [L]
>> >>
>> >>         error_page 404 =404 /index.php;
>> >>
>> >>         index index.php index.html index.htm;
>> >>
>> >>         location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
>> >>                 access_log      off;
>> >>                 expires         30d;
>> >>                 break;
>> >>         }
>> >>
>> >>         ### Proxy CGI to Apache for now
>> >>         location ^~ /scripts/ {
>> >>               proxy_pass http://cgiserver;
>> >>               proxy_set_header X-Real-IP $remote_addr;
>> >>               proxy_set_header Host $host;
>> >>               proxy_set_header X-Forwarded-For
>> > $proxy_add_x_forwarded_for;
>> >>         }
>> >>
>> >>         location ^~ /resources/Detailed/ {
>> >>               proxy_pass http://cgiserver;
>> >>               proxy_set_header X-Real-IP $remote_addr;
>> >>               proxy_set_header Host $host;
>> >>               proxy_set_header X-Forwarded-For
>> > $proxy_add_x_forwarded_for;
>> >>         }
>> >>
>> >> #### Deal with VBSEO Rules
>> >> #RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$
>> > vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
>> >> #RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron)
>> >> #RewriteRule ^((archive/)?(.*\.php(/.*)?)?)$ vbseo.php [L,QSA]
>> >> #RewriteCond %{REQUEST_FILENAME} !-f
>> >> #RewriteCond %{REQUEST_FILENAME} !-d
>> >> #RewriteCond %{REQUEST_FILENAME}
>> > !^(admincp|modcp|clientscript|cpstyles|images)/
>> >> #RewriteRule ^(.+)$ vbseo.php [L,QSA]
>> >>
>> >>         location /forum/ {
>> >>
>> >>         rewrite ^/forum/getnew.html$ /forum/search.php?do=getnew last;
>> >>         rewrite ^/forum/getnew([0-9]+).html$
>> > /forum/search.php?do=getnew&f=$1 last;
>> >>         rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$
>> > /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
>> >>         rewrite ^/forum/unanswered.html$
>> > /forum/search.php?do=process&replyless=1&replylimit=0&dontcache=1 last;
>> >>         rewrite ^/forum/unanswered([0-9]+).html$
>> >
>> /forum/search.php?do=process&replyless=1&replylimit=0&dontcache=1&forumchoice=$1&childforums=1
>> > last;
>> >>
>> >>         if ($request_filename ~ "\.php$" ) {
>> >>                 rewrite ^/forum/(.*)$ /forum/vbseo.php last;
>> >>         }
>> >>
>> >>         if (!-e $request_filename) {
>> >>                 rewrite ^/forum/(.*)$ /forum/vbseo.php last;
>> >>         }
>> >>         }
>> >>
>> >>         location ~ \.php {
>> >>
>> >>                 set $script $uri;
>> >>                 set $path_info "";
>> >>
>> >> #need this bit to work for classifieds friendly urls which need
>> > path_info to be set
>> >>
>> >>                 if ($uri ~ "^(.+\.php)(/.+)") {
>> >>                         set $script $1;
>> >>                         set $path_info $2;
>> >>                 }
>> >>
>> >>             fastcgi_pass   unix:/var/tmp/lighttpd/fastcgi-php.sock;
>> >>             fastcgi_index  index.php;
>> >>             fastcgi_param  SCRIPT_FILENAME  /site/expat/oct08$script;
>> >>             fastcgi_param  PATH_INFO    $path_info;
>> >>             include        fastcgi_params;
>> >>         }
>> >>
>> >>         location ~ /\.ht {
>> >>             deny  all;
>> >>         }
>> >>     }
>> >>
>> >> }
>> >
>> > --
>> > Igor Sysoev
>> > http://sysoev.ru/en/
>>
>
> -- 
> Igor Sysoev
> http://sysoev.ru/en/
>
> 






More information about the nginx mailing list