Log Nginx and PHP after installation of the URL rewrite, access to the blank and hidden index.php file operation method

Source: Internet
Author: User

1 sudo cd/etc/nginx/; 2 sudo vi fastcgi_params;

1.URL rewrite

If your URL parameter is not passed with a. XXX, but is customized, such as with the/xx/xx/xx way, then the Nginx will open PathInfo

Typical configuration:

1 location ~ \. php$ {2    root           html; 3     Fastcgi_pass   127.0.0.1:9000; 4     Fastcgi_index  index.  PHP; 5     Fastcgi_param  script_filename  $DOCUMENT _root$fastcgi_script_name; 6     include         Fastcgi_params; 7 }

Modify 1, 62 lines, support PathInfo

1Location ~ \.php (. *) $ {#regular match. PathInfo section after PHP2 root html;3Fastcgi_pass 127.0.0.1:9000;4Fastcgi_index index.php;5Fastcgi_param Script_filename$DOCUMENT _root$fastcgi_script_name;6Fastcgi_param Path_info $;#assign the PathInfo part to the PATH_INFO variable7     includeFastcgi_params;8}

2. When the URL is rewritten, such as access to xxx/index.php/xxx/xxx will be blank, and access is normal.

A. Modifying the Fastcgi_params file

sudo cd/etc/nginx/; sudo vi fastcgi_params;

Configuration file Contents:

$document _root$fastcgi_script_name; #这行没有就添加, you can change it.

B. Modifying the Nginx configuration file

  

Location ~. php$ {            root           html;            Fastcgi_pass   127.0.0.1:9000;            Fastcgi_index  index. php;            Fastcgi_param  $document _root$fastcgi_script_name# New

include # New
}

3. Hide the entry file

A. If the code is in the root directory that the domain name points to, then

// ... omit part of the code   if $request _filename ) {   rewrite  ^ (. *) $  /index.php?s=$1 last  ;     Break ;    }}

B. If the code is under a subordinate directory that the domain name points to, then

  

   #youdomain is the name of the directory in which it resides. For example, the domain name root directory for the/var/www/html  code is/var/www/html/wave/project, where Youdomain is replaced by wave/projetc
location/youdomain/ { if$request _filename) { rewrite ^/youdomain/(. *) $ /youdomain/index.php?s=$1 last ; } }

===

Log Nginx and PHP after installation of the URL rewrite, access to the blank and hidden index.php file operation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.