NGINX server configuration for Codeigniter



listen 80;
listen [::]:80;
server_name localhost;
root   /var/www/html;
index index.php index.html index.htm;

location / {
    try_files $uri $uri/ =404;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

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

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

location ~ /\.ht {
    deny all;

my codeigniter folder is ‘ci’ which is located in /var/www/html/ci
what configuration do I need to work url rewriting?…


I didn’t want to change the current document root (/var/www/html)
since my ‘ci’ folder is located at /var/www/html/ci.

So instead, I created a new location block in /etc/nginx/conf.d/default.conf:

    location /ci {
        try_files $uri $uri/ /ci/index.php?/$request_uri;

Thanks to Mert Öksüz for suggesting to use try_files $uri $uri/ /ci/index.php?/$request_uri;.

This one also work:

location /ci {
    try_files $uri $uri/ /ci/index.php?$query_string;

Answered By – Amin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published