Nginx虚拟目录(alias)支持PHP配置文件分享

发布时间:2019-08-31编辑:脚本学堂
分享一个nginx虚拟目录中支持php的配置文件,这是个优化版的nginx配置文件,有需要的朋友参考下。

nginx虚拟目录支持php的配置,修正版:
 

复制代码 代码示例:
server {
    listen       80;
    server_name  localhost;
 
    location / {
        root   /pdenv/data/html/;
        index  index.html index.htm index.php;
        autoindex on;
    }
 
    location ~ ^/space/(.*.php)$ {
        alias /pdenv/data/html/Kohana/$1;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    location = /space {
        rewrite ^ $scheme://$host$uri/ permanent;
    }
 
    location /space/ {
        index index.php;
        alias /pdenv/data/html/Kohana/;
    }
 
    location ~ .php$ {
        root           /pdenv/data/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}