Welcome Guest, Not a member yet? Register   Sign In
Problem with query strings using CodeIgniter with nginx
#1

[eluser]mptre[/eluser]
Hi!
I'm having troubles using CodeIgniter with nginx. The setup works fine until a request includes a query string. CodeIgniter then prompts me with a 404.

I've changed the URI protocol to REQUEST_URI in order to work with the CGI. See nginx config below.

Any ideas would be much appreciated! Thanks in advantage!

Code:
server {
    listen 8080;
    server_name *.example.com *.foo.com *.bar.com

    access_log /var/nginx/example.com/m.example.com/logs/access.log;
    error_log /var/nginx/example.com/m.example.com/logs/error.log;

    location / {
        root /var/nginx/example.com/m.example.com/public/current;
        index index.php index.html;

        if (-f $request_filename) {
            break;
        }

        if ($request_filename ~ ^googleb57511441f2b72e1\.html$) {
            break;
        }

        if ($host ~ .*\.(foo|bar)\.com) {
            set $domain $1;
            rewrite ^(.*) http://m.example.com/$domain permanent;
        }

        if ($request_uri ~ ^\/index\.jsp\?d=2104$) {
            rewrite ^(.*) http://m.example.com:8080/tv? permanent;
        }

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

    location /index.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/nginx/example.com/m.example.com/public/current/index.php;
        include /etc/nginx/fastcgi_params;
    }
}
#2

[eluser]Brian Loomis[/eluser]
I'm having the exact same problem right now and it's driving me up the wall. I have to have a query string working and nginx seems to bark at what I'm doing. I even have the 404 going explicitly to index.php with 404 still showing.



server {

listen 192.168.100.194:80;
server_name feed.xyz.com;

access_log /home/webuser/log/access.log;
error_log /home/webuser/log/error.log;

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

# catch all
error_page 404 /index.php;


location / {

# set 404 error page
error_page 404 = /index.php;

# set the doc root
root /var/www/html/feed.xyz.com;

# pass scripts to FastCGI
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi.conf;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/html/feed.xyz.com/index.php;
fastcgi_intercept_errors on;
}


location ~ /\.ht
{
deny all;
}



}
#3

[eluser]mptre[/eluser]
Bump.
#4

[eluser]Unknown[/eluser]
I've the same problem (facebook generates links with query params like ref, so i can't avoid it). I'm using php-fpm wiht 5.3.3 and what i've been found out by sniffing in to the network traffic between nginx and fpm is looks like this:
Code:
QUERY_STRING/some/url/123&ref=nf..REQUEST_METHODGET..CONTENT_TYPE..CONTENT_LENGTH..SCRIPT_NAME/some/index.php.1REQUEST_URI/some/url/123?ref=nf
the request is domain.com/some/url/123?ref=nf.
the nginx conf looks like this (the code is in a subfolder, but that's irrelevant for the problem):
Code:
location /some {
  if (!-e $request_filename) {
    rewrite ^/some/(.*)$ /some/index.php?/$1 last;
  }
}

as you can see, nginx seem to "repair" (replaces ? with a & in $query_string) the bugus query string (after the rewrite it will look like this: domain.com/some/index.php?/url/123?ref=nf), and because of that, the AUTO uri_protocol fails to find the "param" in the $_GET array in search of routing sources in the system/libraries/URI.php:68 (ci version 1.7.2) because of the count($_GET) == 1 condition.

my solution is:
1) use AUTO uri_protocol
2) subclass the CI_URI class, copy the function "_fetch_uri_string" to the new one and remove the count($_GET) == 1 from the condition (original in line 68).
Also enables you to hack back proper GET params from $_SERVER['REQUEST_URI'] but that's is an other story (-:




Theme © iAndrew 2016 - Forum software by © MyBB