cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

middleware:web:nginx:conf:codeigniter.html



Nginx Configuration Examples

Nginx Sample Configuration of Codeigniter

Codeignier Nginx Configuration Example

server {
        listen 80 default_server;

        server_name xx.xx.xx.xx;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ .(php|html|htm)$ {
                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;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include         fastcgi_params;
        }


        ##### CodeIgniter #####
        # https://blog.fire-sign.info/120/
        location /exampledir {
            alias /var/www/html/exampledir;
            index index.php;
            #include /etc/nginx/expires;
            if (!-d $request_filename) {
                rewrite ^/exampledir/(.+)/$ /exampledir/$1 permanent;
            }
            if (!-e $request_filename) {
                rewrite ^/exampledir/(.*)$ /exampledir/index.php?/$1 last;
                break;
            }
        }
        location ~ ^/exampledir/.+.php$ {
            alias /var/www/html/exampledir;
            fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /var/www/html/exampledir/index.php;
            include        fastcgi_params;
        }


        location ~ ^/(application/system)/ {
            deny all;
        }

        location ~ application/.* { deny all; }
        location ~ system/.* { deny all; }
        location ~ /\.ht { deny all; }

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


}








Nginx Configuration Examples




middleware/web/nginx/conf/codeigniter.html.txt ยท Last modified: 2021/02/15 by admin

Page Tools