Nginx, PHP, FastCGI and multiple CodeIgniter apps


#1

Hi!

I’m starting to use nginx and I’m liking. But I can’t get my
CodeIgniter apps working properly.

I was using Apache. To acces the apps I was using:

http:\localhost\app1\index.php<controller><action>
http:\localhost\app2\index.php<controller><action>

I can access the index.php(the default controller/view) sucesfully,
but when I click on other links the page remains the same(the default
controller/action) using this configuration:

this conf goes inside the http section

server {
listen 80;
server_name localhost;

location / {
root /var/www;
index index.html index.htm index.php;
}

pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ .php$ {
include fastcgi_params;
root /var/www;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

# --->

location /clic {
index index.php;
root /var/www;

if ($request_filename !~ (js|css|images|imgs|robots\.txt|index\.php) 

) {
rewrite ^/clic/(.*)$ /clic/index.php/$1 last;
}
}

location ~ /clic/index.php {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/clic/index.php;
}
# —>

#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 /var/www;
}

deny access to .htaccess files, if Apache’s document root

concurs with nginx’s one

location ~ /.ht {
deny all;
}
}


#2

I solved my problem with this configuration:

location ~ .php$ {
include fastcgi_params;
root /var/www;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location /clic {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/clic/index.php;
}

location ~ .(js|ico|gif|jpg|png|css|txt)$ {
root /var/www;
}

/clic is one of my applications.

There was a problem on the URI.php file of CI. It was not working with
the REQUEST_URI protocol to get the URI.
I solved it removing the Base_URL(/clic) from the $_SERVER['REQUEST_URI
'].

Now everything is good =)

Keywords: nginx CodeIgniter configuration