Many users have come across this simple problem: How do i run Codeigniter with Nginx?
This might be a little bit confusing since every single tutorial uses apache and htaccess files. For that reason i'm making this post to settle this problem.
The code below uses PHP-FPM and it's the most basic snippet you can use. I'm assuming that you already have a very basic knowledge on Nginx's config but if you dont a copy/paste on the 'default' file will do the job.
Code:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
index index.php;
root /var/www/vhosts/domain.tld/httpdocs;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
try_files $uri $uri/ /index.php;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?/$1? last;
}
location /index.php {
set $script $uri;
set $path_info $uri;
if ($args ~* "^(/.+)$") {
set $path_info $1;
}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
}
if ($request_uri ~* "^(.*/)index\.php$") {
return 301 $1;
}
}