Nginx Alias 無法解析PHP的解決辦法
Nginx Alias 無法解析PHP的解決辦法:
server {
??????? listen?????? 80;
??????? server_name? xxxx.com.cn;
??????? error_log? /tmp/eror.log;
??????? set $www_root /home/web/yqbb/bgskk;
??????? location / {
??????????? root?? $www_root;
??????????? index? index.html index.php;
??????? }
??????? location /feedback {
??????????? index? index.php;
??????????? alias /home/web/yqbb/bgskk/app/htdocs;
??????? }
??????? error_page?? 500 502 503 504? /50x.html;
??????? location = /50x.html {
??????????? root?? html;
??????? }
??????? location ~ ^/feedback/.+\.php$ {
??????????????? root /home/web/yqbb/bgskk/app/htdocs;
??????????????? rewrite /feedback/(.*\.php?) /$1 break;
??????????????? include fastcgi.conf;
??????????????? fastcgi_pass?? 127.0.0.1:9000;
??????????????? fastcgi_index? index.php;
??????????????? fastcgi_param SCRIPT_FILENAME /home/web/yqbb/bgskk/app/htdocs/$fastcgi_script_name;
??????? }
??????? location ~ .*\.(php|php5)?$ {
??????????????? fastcgi_pass? 127.0.0.1:9000;
??????????????? fastcgi_index index.php;
??????????????? include fastcgi.conf;
??????? }
??? }
?
?
server
??? {
??????? listen 80;? #連接埠號碼
??????? server_name www.linuxidc.com;?? #網域名稱
??????? index index.html index.htm index.php index.shtml;? #預設首頁
??????? root? /var/www/html;? #網站根目錄
??????? charset gbk;??? #預設編碼
??????? location /public/? #設定要重寫的目錄名
??????? {
??????????????? alias /var/www/public/; #重新導向目的目錄。
??????????????? #例:如果使用者訪問http://www.linuxidc.com/public/test.html 不會訪問/var/www/html/public/test.html,而訪問的是/var/www/public/test.html,雖然這個檔案並沒有在網域名稱目錄下
??????? }
#做完上面的設定後,我們發現訪問PHP檔案http://www.linuxidc.com/public/test.php時,還是去訪問了/var/www/html/public/test.php,也就是說訪問php檔案沒有起到重新導向的作用,所以我們還要配置如下這段
#start
??????? location ~ ^/public/.+\.php$
??????? {
??????????????? root /var/www/html/web/news/public;
??????????????? rewrite /public/(.*\.php?) /$1 break;
??????????????? include fastcgi.conf;
??????????????? fastcgi_pass?? 127.0.0.1:9000;
??????????????? fastcgi_index? index.php;
??????? }
#end
??????? location ~ .*\.(php|php5)?$
??????? {
??????????? #fastcgi_pass? unix:/tmp/php-cgi.sock;
??????????? fastcgi_pass? 127.0.0.1:9000;
??????????? fastcgi_index index.php;
??????????? #include fcgi.conf;
??????????? include fastcgi.conf;
??????????? rewrite? ^/([a-zA-Z]+)\/([a-zA-Z]+)$ /$2.shtml last;
??????? }
??????? location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
??????? {
??????????? expires????? 30d;? #緩衝30天
??????? }
??????? location ~ .*\.(js|css)?$
??????? {
??????????? expires????? 1h; #緩衝1個小時
??????? }
??????? access_log? /var/log/linuxidc.log? access;? #定義記錄檔
??????? ssi on;
??????? ssi_silent_errors on;
??????? ssi_types text/shtml;
??? }