CodeIgniter Forums
NGINX / htaccess woes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: NGINX / htaccess woes (/showthread.php?tid=68495)



NGINX / htaccess woes - microbluechip - 07-19-2017

Hey all.

We are moving from an Apache setup to a NGINX setup (under a dockerised environment)
and struggling to get CI 3.1.5 to work properly.

Has anyone ever got CI working correctly under NGINX.
I'm pretty sure it's to do with converting htaccess rules to their NGNIX equivalents.

Here is my vhost configuration so far :-


server {
        listen 80;
        listen [::]:80;

        root /app/staging;
        index index.php;

        server_name _;

                location / {
                        if (!-e $request_filename) {
                                rewrite ^(.*)$ /index.php?/$1
                                break;
                        }
                }

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

        # set expiration of assets to MAX for caching
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

        location ~* \.php$ {
                fastcgi_pass php5:9000;
                include fastcgi.conf;
        }

        location ~ /\.ht {
                deny all;
        }
}

Does anyone have any experience with this as the rewrite rules are not passing the path info over to index.php correctly and not sure how to diagnose.

Thanks in advance.
Phil.


RE: NGINX / htaccess woes - Hussein Elturkey - 08-06-2017

i have the same problem, can not remove index.php over ngin, tried every thing but nothing is working


RE: NGINX / htaccess woes - InsiteFX - 08-07-2017

You can try this .htaccess file from FuelPHP seems to work with a lot
of different setups.

Code:
# Multiple Environment config, set this to development, staging or production
# SetEnv FUEL_ENV production

<IfModule mod_rewrite.c>

    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    #RewriteBase /wherever/fuel/is

   # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes

    # Restrict your site to only one domain
    # !important USE ONLY ONE OPTION

    # Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    #RewriteCond %{HTTP_HOST} (.+)$ [NC]
    #RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

    # Remove index.php from URL
    #RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
    #RewriteCond %{THE_REQUEST}                ^[^/]*/index\.php [NC]
    #RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

   # make HTTP Basic Authentication work on php-fcgi installs
   <IfModule mod_fcgid.c>
       RewriteCond %{HTTP:Authorization} .
       RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   </IfModule>

    # Send request via index.php if not a real file or directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # deal with php-fcgi first
    <IfModule mod_fcgid.c>
       RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>

    # no php-fcgi, check for sapi and fpm
    <IfModule !mod_fcgid.c>

        # for PHP5 sapi installations
        <IfModule mod_php5.c>
            RewriteRule ^(.*)$ index.php/$1 [L]
        </IfModule>

        <IfModule !mod_php5.c>

            # for PHP7 sapi installations
            <IfModule mod_php7.c>
                RewriteRule ^(.*)$ index.php/$1 [L]
            </IfModule>

            # for fpm installations
            <IfModule !mod_php7.c>
                RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
            </IfModule>

        </IfModule>

    </IfModule>

</IfModule>



RE: NGINX / htaccess woes - abubasil - 08-24-2017

Same here, CodeIgniter does not function in real website server. the A.M solution does not work either.


RE: NGINX / htaccess woes - Happy Camper - 08-26-2017

Hello

There is an example config at

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

Just change

Code:
   

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

to

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

and it should work fine.