Home >Backend Development >PHP Tutorial >Nginx directory alias Alias ​​supports PHP configuration

Nginx directory alias Alias ​​supports PHP configuration

WBOY
WBOYOriginal
2016-08-08 09:22:171807browse
Requirement: /var/data/www is accessed through example.com, but /var/data/phpmyadmin is accessed through example.com/pa, which protects phpmyadmin from being exposed in the www directory. 1. Method 1: (not recommended)Introduction: This is the Rewrite method commonly used on the Internet.
Defects: Simple php programs can handle it, but more complex programs have "No input file specified"

01.server {

02.listen 80;

03.server_name example.com;

04.

05.root /var/data/www;

06.index index.html index.php;

07.

08.location /pa {

09.alias /var/data/phpmyadmin;

10.index index.html index.php;

11.}

12. 

13.location ~ /pa/.+.php$ {

14.rewrite /pa/(.+.php) /$1 break;

15.fastcgi_pass  127.0.0.1:9000;

16.fastcgi_index  index.php;

17.fastcgi_param  SCRIPT_FILENAME  /var/data/phpmyadmin/$fastcgi_script_name;

18.include  fastcgi_params;

19.}

20. 

21.location ~ .+.php.*$ {

22.fastcgi_pass  127.0.0.1:9000;

23.fastcgi_index  index.php;

24.fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;

25.fastcgi_param  SCRIPT_FILENAME  $request_filename;

26.include  fastcgi_params;

27.}

28.}

2. Method 2: (Recommended) Introduction: Perfect implementation, No side effects.
Features: A variable called "$valid_fastcgi_script_name" is used

View code Print code help

01.server {

02.listen 80;

03.server_name example.com;

04.

05.root /var/data/www;

06.index index.html index.php;

07. 

08.location /pa {

09.alias /var/data/phpmyadmin;

10.index index.html index.php;

11.}

12. 

13.location ~ /pa/.+.php.*$ {

14.if ($fastcgi_script_name ~ /pa/(.+.php.*)$) {

15.set $valid_fastcgi_script_name $1;

16.}

17.fastcgi_pass  127.0.0.1:9000;

18.fastcgi_index  index.php;

19.fastcgi_param  SCRIPT_FILENAME  /var/data/phpmyadmin/$valid_fastcgi_script_name;

20.include  fastcgi_params;

21.}

22. 

23.location ~ .+.php.*$ {

24.fastcgi_pass  127.0.0.1:9000;

25.fastcgi_index  index.php;

26.fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

27.fastcgi_param SCRIPT_FILENAME $request_filename;

28.include fastcgi_params;

29.}

30.}

2. Method 3: Introduction: View at zhigang.net The creative method I came up with is to add two server fields to one site, and then implement it through reverse generation.
Specific: The method is creative and a little troublesome.

The above introduces the configuration of Nginx directory alias Alias ​​to support PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn