can some1 please convert this htaccess to nginx rewrite?

Igor Sysoev is at rambler-co.ru
Fri Jan 16 15:09:48 MSK 2009


On Thu, Jan 15, 2009 at 10:41:02PM +0100, Lemon Head wrote:

> Igor Sysoev wrote:
> > On Thu, Jan 15, 2009 at 08:53:55PM +0100, Lemon Head wrote:
> > 
> >> to the .php file is /usr/share/nginx/html/forum
> >> another small problem i have is that if i get into
> >> http://mysite/forum it doesnt load the page,but if i add
> >> a secondary slash however as in /forum/ it works fine
> >> how can i fix it? thanks in advance
> > 
> > Something like this:
> > 
> >      location /forum {
> >          fastcgi_pass  ...;
> >          fastcgi_param  SCRIPT_FILENAME 
> > /usr/share/nginx/html/forum/show.php;
> >          include        fastcgi_params;
> >      }
> 
> first of,thx for your help
> i tried that but then nginx failed to start
> with this error: "Starting nginx: 2009/01/15 16:36:41 [emerg] 23287#0: 
> location "/forum" is outside location "/forum/" in 
> /etc/nginx/nginx.conf:121"

If you properly format configuration:

         # vbseo rewrite
         location /forum/ {
             rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ 
                  /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
 
             if (-f $request_filename) {
                 expires 30d;
                 break;
             }
 
             if ($request_filename ~ "\.php$" ) {
                 rewrite ^(/forum/.*)$ /forum/vbseo.php last;
             }
 
             if (!-e $request_filename) {
                 rewrite ^/forum/(.*)$ /forum/vbseo.php last;
             }
 
             location /forum {
                  fastcgi_pass   ...;
                  fastcgi_param  SCRIPT_FILENAME
                                 /usr/share/nginx/html/forum/show.php;
                  include        fastcgi_params;
             }
         }

then you will see that /forum is inside /forum/:

         location /forum/ {
             ...
             location /forum {

You should use somethig like this:

     location = /forum {
         fastcgi_pass   localhost:9000;
         fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html/forum/show.php;
         include        fastcgi_params;
     }

     location ~ ^/forum/vbseo_sitemap/.+\.php$ {
         fastcgi_pass   localhost:9000;
         fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html/$uri;
         include        fastcgi_params;
     }

     location ~ ^/forum/.+\.php$ {
         fastcgi_pass   localhost:9000;
         fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html/forum/vbseo.php;
         include        fastcgi_params;
     }

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

         error_page  404  = /forum/vbseo.php;

         expires 30d;
     }

> heres my whole config , maybe it will help
> 
> #######################################################################
> #
> # This is the main Nginx configuration file.
> #
> # More information about the configuration options is available on
> #   * the English wiki - http://wiki.codemongers.com/Main
> #   * the Russian documentation - http://sysoev.ru/nginx/
> #
> #######################################################################
> 
> #----------------------------------------------------------------------
> # Main Module - directives that cover basic functionality
> #
> #   http://wiki.codemongers.com/NginxMainModule
> #
> #----------------------------------------------------------------------
> 
> user              nginx;
> worker_processes  5;
> 
> error_log         /var/log/nginx/error.log;
> #error_log        /var/log/nginx/error.log  notice;
> #error_log        /var/log/nginx/error.log  info;
> 
> pid               /var/run/nginx.pid;
> 
> 
> 
> #----------------------------------------------------------------------
> # Events Module
> #
> #   http://wiki.codemongers.com/NginxEventsModule
> #
> #----------------------------------------------------------------------
> 
> events {
>     worker_connections  1024;
> }
> 
> 
> #----------------------------------------------------------------------
> # HTTP Core Module
> #
> #   http://wiki.codemongers.com/NginxHttpCoreModule
> #
> #----------------------------------------------------------------------
> 
> http {
>     include       /etc/nginx/mime.types;
>     default_type  application/octet-stream;
> 
>     log_format  main  '$remote_addr - $remote_user [$time_local] 
> $request '
>                       '"$status" $body_bytes_sent "$http_referer" '
>                       '"$http_user_agent" "$http_x_forwarded_for"';
> 
>     access_log  /var/log/nginx/access.log  main;
> 
>     sendfile        on;
>     #tcp_nopush     on;
> 
>     #keepalive_timeout  0;
>     keepalive_timeout  2;
> 
> 
>     gzip  on;
> 
>     # Load config files from the /etc/nginx/conf.d directory
>     include /etc/nginx/conf.d/*.conf;
> 
>     #
>     # The default server
>     #
>     server {
>         listen       80;
>         server_name  _;
> 
>         #charset koi8-r;
> 
>         #access_log  logs/host.access.log  main;
> 
>         location / {
>             root   /usr/share/nginx/html;
>             index  index.html index.php index.htm;
>         }
> 
>         error_page  404              /404.html;
>         location = /404.html {
>             root   /usr/share/nginx/html;
>         }
> 
>         # redirect server error pages to the static page /50x.html
>         #
>         error_page   500 502 503 504  /50x.html;
>         location = /50x.html {
>             root   /usr/share/nginx/html;
>         }
> 
>         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
>         #
>         #location ~ \.php$ {
>         #    proxy_pass   http://127.0.0.1;
>         #}
> 
>         # vbseo rewrite
>         location /forum/ {
>          rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ 
> /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
> 
>         if (-f $request_filename) {
>         expires 30d;
>         break;
>         }
> 
>        if ($request_filename ~ "\.php$" ) {
>        rewrite ^(/forum/.*)$ /forum/vbseo.php last;
>        }
> 
>        if (!-e $request_filename) {
>        rewrite ^/forum/(.*)$ /forum/vbseo.php last;
>        }
> 
>      location /forum {
>          fastcgi_pass  ...;
>          fastcgi_param  SCRIPT_FILENAME
> /usr/share/nginx/html/forum/show.php;
>          include        fastcgi_params;
>      }
>        }
> 
>         # pass the PHP scripts to FastCGI server listening on 
> 127.0.0.1:9000
>         #
>         location ~ \.php$ {
>             root           /usr/share/nginx/html;
>             fastcgi_pass   127.0.0.1:9000;
>             fastcgi_index  index.php;
>             fastcgi_param  SCRIPT_FILENAME 
> /usr/share/nginx/html$fastcgi_script_name;
>             include        fastcgi_params;
>         }
> 
> 
>         # deny access to .htaccess files, if Apache's document root
>         # concurs with nginx's one
>         #
>         location ~ /\.ht {
>             deny  all;
>         }
>     }
> }
> -- 
> Posted via http://www.ruby-forum.com/.

-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list