Nginx hides index.php and Pathinfo mode configuration examples

  • 2020-05-07 20:51:54
  • OfStack

Refer to the corresponding modification under 1 and restart nginx


server {
        listen       80;
        server_name www.leiyongbo.com www.leiyongbo.com;
        root /usr/local/web;
        index index.php;
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  405 /errpage/405.html;

        ########################################### hidden index.php
        location / {
                if (!-e $request_filename) {

                        ###1 Level directory 
                        rewrite ^/(.*)$ /index.php/$1 last;

                        ### Under the domain of 2 Level directory 
                        #rewrite ^/ Directory name /(.*)$ / Directory name /index.php/$1 last;
                }   
        }

        ##########################################pathinfo  model 
        location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}


Related articles: