Join the community today
Become a Member

NGINX question for you wizards...

Discussion in 'Other Web Apps usage' started by fly, Apr 28, 2023.

  1. fly

    fly Member

    109
    16
    18
    Jul 27, 2019
    Ratings:
    +28
    Local Time:
    9:42 AM
    I know this isn't an NGINX support forum, but I figured I'd try here anyway. I have a client with a codebase written in CodeIgniter that I can't get working in Centminmod. It's two different domains with the backend being the problem. The actual URL pattern looks like this:


    domain.com/index.php/api/data

    But we're trying to use pretty links so that the URL looks like this: domain.com/api/data

    I was able to get that to work by adding this to the .conf:

    Code:
      if (!-e $request_filename) {
          rewrite ^.*$ /index.php last;
      }
    
    But that breaks CORS because it seemingly removes headers. Clearly I'm not an NGINX expert, so what am I missing here?
     
  2. eva2000

    eva2000 Administrator Staff Member

    51,696
    11,941
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,432
    Local Time:
    11:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    It comes down to how Centmin Mod's default php.conf include file parses/processes *.php files - you can see similar solution at https://community.centminmod.com/threads/anyone-using-osticket-with-microsoft-365-auth2.23592/

    the issue is how Centmin Mod PHP-FPM defines path_info by default. You'd need to make a copy of /usr/local/nginx/conf/php.conf like /usr/local/nginx/conf/php_codeigniter.conf
    Code (Text):
    cp -a /usr/local/nginx/conf/php.conf /usr/local/nginx/conf/php_codeigniter.conf
    

    Then edit /usr/local/nginx/conf/php_codeigniter.conf by changing first line from
    Code (Text):
    location ~ [^/]\.php(/|$) {
    

    to
    Code (Text):
    location ~ \.php$ {
    

    Then edit /usr/local/nginx/conf/php_codeigniter.conf comment out with hash # in front
    Code (Text):
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
    

    Then edit /usr/local/nginx/conf/php_codeigniter.conf, change from
    Code (Text):
    fastcgi_param  PATH_INFO          $fastcgi_path_info;

    to
    Code (Text):
    fastcgi_param  PATH_INFO    $path_info;

    Then edit nginx vhost /usr/local/nginx/conf/conf.d/yourdomain.com.ssl.conf and replace php.conf include file /usr/local/nginx/conf/php.conf with /usr/local/nginx/conf/php_codeigniter.conf
    Then restart nginx and php-fpm services
    Code (Text):
    nprestart
    

    Might not be perfect, so you'd have figure it out from there depending on how Codeigniter works
     
  3. fly

    fly Member

    109
    16
    18
    Jul 27, 2019
    Ratings:
    +28
    Local Time:
    9:42 AM
    It doesn't seem to like the $path_info in the new php.conf

    Code:
    nginx: [emerg] unknown "path_info" variable
    
    edit: I see that path_info is from the other thread. I added this in the server section (in my case using api_v2), but it didn't seem to help.
    Code:
    if ($request_uri ~ "^/api_v2(/[^\?]+)") {
        set $path_info $1;
    }
    
     
    Last edited: Apr 29, 2023
  4. eva2000

    eva2000 Administrator Staff Member

    51,696
    11,941
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,432
    Local Time:
    11:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    in /usr/local/nginx/conf/php_codeigniter.conf, switch back to using
    Code (Text):
    fastcgi_param PATH_INFO $fastcgi_path_info;

    Code (Text):
    nprestart
     
  5. fly

    fly Member

    109
    16
    18
    Jul 27, 2019
    Ratings:
    +28
    Local Time:
    9:42 AM
    Still getting a 404. The error seems to indicate that its still not putting that /index.php/ into the path.