归档文章 (2011-2017)
date
2012/03/30
需求:通过 example.com 访问
/var/data/www
,但通过 example.com/pa 访问的却是 /var/data/phpmyadmin,即保护phpmyadmin不暴露在www目录下。一、方法一:(不推荐)
简介:这是网上普遍采用的 Rewrite 方式。
缺陷:简单的php程序还能应付,复杂一点的程序就
No input file specified
server { listen 80; server_name example.com; root /var/data/www; index index.html index.php; location /pa { alias /var/data/phpmyadmin; index index.html index.php; } location ~ /pa/.+\.php$ { rewrite /pa/(.+\.php) /$1 break; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/data/phpmyadmin/$fastcgi_script_name; include fastcgi_params; } location ~ .+\.php.*$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; } }
二、方法二:(推荐)
简介:完美实现,无副作用。
特点:使用了一个叫
$valid_fastcgi_script_name
的变量server { listen 80; server_name example.com; root /var/data/www; index index.html index.php; location /pa { alias /var/data/phpmyadmin; index index.html index.php; } location ~ /pa/.+\.php.*$ { if ($fastcgi_script_name ~ /pa/(.+\.php.*)$) { set $valid_fastcgi_script_name $1; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/data/phpmyadmin/$valid_fastcgi_script_name; include fastcgi_params; } location ~ .+\.php.*$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; } }
二、方法三:
简介:在 http://www.zhigang.net/post/1001 上看到的创意方法,即一个站加两个server字段,然后通过反代的方式实现。
特定:方法有创意,稍微麻烦点。