Alexd2
Alexd2

Reputation: 1114

nginx with rewrite

Just perform an installation of Nginx, PHP, following this tutorial and all is well. Upon entering the url http://192.168.1.10 shows me the welcome screen. Now create a folder called test and want to implement something like apache mod-rewrite, so that upon entering http://192.168.1.10/test/my-test/ call index.php?x=my-test

The modified sites-avaible/default looks like this:

server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        #root /usr/share/nginx/www;
        root /var/www/;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                #try_files $uri $uri/ /index.html;
        }

        location /test{
                if (-f $request_filename) {
                        break;
                }
                if (-d $request_filename) {
                        break;
                }
                rewrite ^(.+)/$ /index.php?x=$1 last;
        }

        location /doc {
                root /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location /images {
                root /usr/share;
                autoindex off;
        }
        #error_page 404 /404.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/www;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #       proxy_pass http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_pass unix:/tmp/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

It does not work as expected. If I go to http://192.168.1.10/test/my-test/ what happens is it shows me the value of the index of http://192.168.1.10/.

Attached image

Upvotes: 0

Views: 1185

Answers (2)

Freeman Zhang
Freeman Zhang

Reputation: 175

Use this rewrite Rule: rewrite /test/(.*) /index.php?x=$1 last;

Upvotes: 1

Waseem
Waseem

Reputation: 43

May be you can try this:

try_files $uri $uri/ /index.php?q=$uri&$args;

Zend framework will translate arguments in its convention once they reach index.php properly formatted.

Upvotes: 1

Related Questions