Nginx目錄別名(Alias)支援PHP的配置

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   使用   ar   sp   

需求:通過 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;    }}
二、方法三:

簡介:在 zhigang.net 上看到的創意方法,即一個站加兩個server欄位,然後通過反代的方式實現。
特定:方法有創意,稍微麻煩點。

Nginx目錄別名(Alias)支援PHP的配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.