Welcome Guest, Not a member yet? Register   Sign In
when I change web server from Apache2 to nginx,how can set rewrite?
#1

[eluser]chmod[/eluser]
install Ci in nginx,how to set rewrite?
if in apche2,I will setup like this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

how can i do in nginx?
thanks
#2

[eluser]Pascal Kriete[/eluser]
Does the method Popcorn describes in this post work for you?
#3

[eluser]chmod[/eluser]
I will try it.thanks Pascal Kriete.

my nginx.conf is like this:


user nginx nginx;
worker_processes 10;

error_log logs/error.log;
pid logs/nginx.pid;


events {
use epoll;
worker_connections 1024;
}

http {
include 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 logs/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;

server {

listen 80;
root /var/www/myproject/;
charset utf-8;
access_log logs/host.access.log main;
index index.php index.html index.htm;

error_page 500 502 503 504 /50x.html;

location / {
if (-f $request_filename) {
expires max;
break;
}

if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
}
}

location = /50x.html {
root /var/www/;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:10005;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/myproject/$fastcgi_script_name/;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}
}

but it can't work.
error log:


2008/12/21 01:07:08 [error] 4270#0: *1 rewrite or internal redirection cycle while processing "/index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php//kohana/index.php/examples/calendar", client: 127.0.0.1, server: liujun-laptop, request: "GET /kohana/index.php/examples/calendar HTTP/1.1", host: "localhost", referrer: "http://localhost/"
#4

[eluser]Matthieu Fauveau[/eluser]
Hi chmod,

This is what I have done to get CodeIgniter rewriting under Nginx (of course you will have to had this inside the server { }) :

Code:
# rewriting for CodeIgniter
    location / {
        index index.php;
            root  /path/to/your/htdocs;

        if (-f $request_filename) {
            expires    30d;
            access_log off;
        }

        if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
            }
     }

    # handle php for CodeIgniter
    location ~ /index.php/ {
            fastcgi_index   index.php;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_param   SCRIPT_FILENAME /path/to/your/htdocs/index.php;
                include /etc/nginx/fastcgi_params;
        }

You will also have to change your config.php file like this:
Code:
$config['uri_protocol']    = "REQUEST_URI";

That should work!
#5

[eluser]chmod[/eluser]
[quote author="Matthieu Fauveau" date="1231902703"]Hi chmod,

This is what I have done to get CodeIgniter rewriting under Nginx (of course you will have to had this inside the server { }) :

Code:
# rewriting for CodeIgniter
    location / {
        index index.php;
            root  /path/to/your/htdocs;

        if (-f $request_filename) {
            expires    30d;
            access_log off;
        }

        if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
            }
     }

    # handle php for CodeIgniter
    location ~ /index.php/ {
            fastcgi_index   index.php;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_param   SCRIPT_FILENAME /path/to/your/htdocs/index.php;
                include /etc/nginx/fastcgi_params;
        }

You will also have to change your config.php file like this:
Code:
$config['uri_protocol']    = "REQUEST_URI";

That should work![/quote]



it's work.but $_GET cannot used.
In my project, I use $.getJSON and like dialog.js?key=random(),
if I change $config['uri_protocol'] = "PATH_INFO";
TO
$config['uri_protocol'] = "REQUEST_URI";
it's not work.
#6

[eluser]Unknown[/eluser]
i have same problem..
is this post fixed?
need help...
thank you...
#7

[eluser]nil_php[/eluser]
Hi friends I have same problem. I want to use PATH_INFO with nginx because my tracking url like abc.com/search?a_aid=12345

Please help us to use $config['uri_protocol'] = "PATH_INFO"; with nginx.




Theme © iAndrew 2016 - Forum software by © MyBB