0

I am new on nginx and try to find the issue on StackOverflow but not found the exact one on forums. After successful installation of nginx, MySQL and php-fpm I test the php.info that was working fine.

I am moving the CodeIgniter project to the nginx from apache server. I edit the nginx.conf file that has code

server {
    listen       80;
    server_name  173.249.40.xxx;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html/ci;
    index index.html index.htm index.php;

    location /ci {
        try_files $uri $uri/ /index.php;
    }        

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/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;
    }
}

it was working fine for php.info like my path is http://173.249.40.xxx/ci/info.php but not working for CodeIgniter controller name like http://173.249.40.xxx/ci/index.php/Welcome when called.

The CodeIgniter application path is '/usr/share/nginx/html/ci/;'

Please suggest me something. how can I fix it?

NomanJaved
  • 111
  • 1
  • 7

2 Answers2

1

Here is the error:

    location /ci {

Because of this, only URL paths which start with /ci will be processed by the enclosing try_files. This is not what you want.

Instead, you should have all URLs processed, with

    location / {
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

I recommend not editing the nginx.conf file. Only edit gzip and a new include folder (like include /etc/nginx/sites/enabled/*.conf;), comment out the original include row and create your config file there with the name com.mywebsite.conf to the folder I've mentioned before.

This is how I've done it in the past:

In the new config file I've mentioned, copy the content of the officially recommended config, that should work if you modify the variables to your system.

https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/

Also, store your websites in /var/www/html/mywebsite

Bert
  • 1,028
  • 1
  • 16
  • 33