Hi, I just recently tried to setup my CI project on Nginx. I’m using Nginx 1.0.0 (Stable) on Amazon Micro Linux AMI.
This is the best I could come for the configuration:
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
upload_progress uploads 100M;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name ec2-175-41-199-2.ap-northeast-1.compute.amazonaws.com;
client_max_body_size 10m;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/local/nginx/html;
index index.php index.html index.htm;
}
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you
# should change the following
if ($request_uri ~* ^(/album(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# removes access to "system" folder, also allows a "System.php"
# controller
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# unless the request is for a valid file (image, js, css, etc.), send
# to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
#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 html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
}
Because my solution is so messed up, I had to zero-length the base_url in order for it to work. Because if I put something in there, it gets prefixed to the main URL. For example if the URL the user is using to get to my site is mysite.com/welcome/index the final URL becomes mysite.com/mysite.com/welcome/index. It’s very bad, the only solution I found to fix it is this.
$config['base_url'] = '';
Additionally, when using my configuration (which btw is a fusion of other people’s configuration), you have to include this:
$config['uri_protocol'] = 'REQUEST_URI';
And I don’t know why. But thankfully, with that configuration it works pretty well. I do have a still unsolved problem with file uploads. I still can’t receive file uploads. And I’m still figuring out why. 😖