CodeIgniter Forums

Full Version: NGINX Codeigniter 4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear forum users/administrators


I'm trying to setup Codeigniter 4 with nginx .

The problem is the following whenever i try to take a correct route (works on apache) i get this error 'Controller or its method is not found: \App\Controllers\dashboard::index' even though it exists.

this is my configuration:

Code:
server {
    if ($host = dashboard.example.com) {
        return 301 https://$host$request_uri;
    } 


listen 80;
listen [::]:80;

  set_real_ip_from  0.0.0.0/0;
  real_ip_header    X-FORWARDED-FOR;
  real_ip_recursive on;



root /var/www/dashboard.example.com/public;

index index.php index.html index.htm index.nginx-debian.html;

server_name dashboard.example.com;

  location / {
                try_files $uri $uri/ /index.php;
        }
location ~ \.php$
            {
                try_files $uri =404;
                fastcgi_pass  unix:/var/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
            }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

        location ~ .*\.(js|css)?$
            {
                expires      12h;
            }







}




server {




    set_real_ip_from  0.0.0.0/0;



    real_ip_header proxy_protocol;



    real_ip_recursive on;


root /var/www/dashboard.example.com/public;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
    server_name dashboard.example.com; # managed by Certbot

  location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri $uri/ /index.php;
        }
location ~ \.php$

            {
                try_files $uri =404;
                fastcgi_pass  unix:/var/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
            }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

        location ~ .*\.(js|css)?$
            {
                expires      12h;
            }

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}


    listen 443 ssl proxy_protocol;


    ssl_certificate /etc/letsencrypt/live/dashboard.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dashboard.example.com/privkey.pem; # managed by Certbot
}
server {
    if ($host = dashboard.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


listen 80 ;
listen [::]:80 ;
    server_name dashboard.example.com;
    return 404; # managed by Certbot


}
You currently got two port 80-configurations. Do you get this error on both http and https?

Have you tried the sample nginx configuration from the userguide?
https://codeigniter.com/user_guide/insta...with-nginx

It's written for Ubuntu and PPA Nginx.
https://launchpad.net/~ondrej/+archive/ubuntu/nginx

I'm not sure what's in your fastcgi.conf but fastcgi-php.conf contains this:
Code:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?\.php)(/.*)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;