You are not logged in.

#1 2010-04-08 07:56:41

Gruntz
Member
From: Haskovo, Bulgaria
Registered: 2007-08-31
Posts: 291

[SOLVED] nginx, php-cgi, rewrite url, 502 bad gateway.

Hello everyone.

I just set my nginx server, with php-cgi, as it is in the wiki site and it is working perfectly. I have just one problem. I am trying to rewrite my url, and I got an error after several refreshes.

This is my site configuration.

    server {
        listen 80;
        server_name localhost testwebsite testwebsite.homelinux.org;
        access_log  logs/testwebsite.access.log  main;


        location / {
            root   /home/www/testwebsite;
            index  index.php;
        }

        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php?path=$1 last;
              #rewrite ^/((.*)[^/])$ /index.php?path=$1 last;
        }

        location ~ \.php$ {
            #root           www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/www/testwebsite/$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

When I am not trying to rewrite the url, everything is ok, but when I try to rewrite it, after several refreshes on the page, I got nginx error: 502 bad gateway, and the cgi deamon stops to work.

When I restart the fastcgi (I am using the example /etc/rc.d/fastcgi file as it is in the wiki) the web site is working again for several refreshes, and then the fastcgi stops again and I got the bad gateway again.

Can someone tell me what is wrong with my rewrite rule, please.

Regards.

Last edited by Gruntz (2010-04-08 15:58:50)

Offline

#2 2010-04-08 15:58:37

Gruntz
Member
From: Haskovo, Bulgaria
Registered: 2007-08-31
Posts: 291

Re: [SOLVED] nginx, php-cgi, rewrite url, 502 bad gateway.

I fixed it with that rewrite:

rewrite  ^([^.]*)$  /index.php?path=$1;

Offline

Board footer

Powered by FluxBB