假若在網址上打上 http://www.examplepppp.com/A1/ 連結到的網頁實記錄徑為 /var/www/html/happy/index.php,要實現這樣結果就必須搭配 Nginx的Alias及rewrite或Nginx 內建變數 “$valid_fastcgi_script_name”。以下展示範例
~略~ server { listen 80; server_name www.examplepppp.com; root /var/www/html/; index index.html index.php; location /A1/ { alias /var/www/html/happy/; index index.html index.php; } location ~ /A1/.*\.php$ { if ($fastcgi_script_name ~ /A1/(.*\.php)$) { set $valid_fastcgi_script_name $1; } fastcgi_pass 127.0.0.1:10004; fastcgi_param SCRIPT_FILENAME /var/www/html/A1/$valid_fastcgi_script_name; } }