配置nginx下别名alias支持PHP fastcgi解析
2013-08-07 13:16
405 查看
1)参看如下连篇文章:
Nginx设置alias实现虚拟目录 alias与root的用法区别 http://down.chinaz.com/server/201111/1382_1.htm Nginx下alias支持PHP的问题 http://i.laoer.com/nginx-alias-php.html
2)我的环境是:web根目录在 /var/www/html/中,但是我要加上一个类似于apache的别名目录 /bbs ,此目录不在 web根目录中。
我的配置文件如下:
server {
listen 80;
server_name localhost;
default_type text/plain;
location / {
root /var/www/html;
index index.php index.htm index.html;
}
location = /extension/sub {
set $push_channel_id $arg_exten;
push_subscriber long-poll;
push_subscriber_concurrency broadcast;
push_channel_group broadcast;
default_type text/plain;
#default_type text/html;
}
location = /extension/pub {
set $push_channel_id $arg_exten;
push_publisher;
push_min_message_buffer_length 0;
push_max_message_buffer_length 0;
push_message_timeout 1h;
push_channel_group broadcast;
default_type text/plain;
#default_type text/html;
}
location /bbs {
alias /opt/bbs/;
index index.html index.htm index.php;
}
location ~ ^/bbs/.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt$fastcgi_script_name;
include fastcgi_params;
#include fastcgi.conf;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
#include fastcgi.conf;
}
}
说明: 上面这个就是成功的例子。但是又如下几点需要注意:
1)location ~ \.php$ {} 段,必须放在 location ~ ^/bbs/.+\.php$ {} 段后面,否则/bbs/的url打不开
2) location ~ ^/bbs/.+\.php$ {} 里面也可以写成如下:
location ~ ^/bbs/.+\.php$ {
root /opt;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
也就是用 变量名 $document_root 代替 /opt; 其实每个 location {}中的 $document_root 都是局部变量,都是在本段配置 root指令指定的路径。
以上配置完全可以通过nginx的第3放插件 echo 模块来得到验证,方法如下:
location /echo {
root /etc/asterisk;
#echo "$document_root";
echo "$fastcgi_script_name";
}
Nginx设置alias实现虚拟目录 alias与root的用法区别 http://down.chinaz.com/server/201111/1382_1.htm Nginx下alias支持PHP的问题 http://i.laoer.com/nginx-alias-php.html
2)我的环境是:web根目录在 /var/www/html/中,但是我要加上一个类似于apache的别名目录 /bbs ,此目录不在 web根目录中。
我的配置文件如下:
server {
listen 80;
server_name localhost;
default_type text/plain;
location / {
root /var/www/html;
index index.php index.htm index.html;
}
location = /extension/sub {
set $push_channel_id $arg_exten;
push_subscriber long-poll;
push_subscriber_concurrency broadcast;
push_channel_group broadcast;
default_type text/plain;
#default_type text/html;
}
location = /extension/pub {
set $push_channel_id $arg_exten;
push_publisher;
push_min_message_buffer_length 0;
push_max_message_buffer_length 0;
push_message_timeout 1h;
push_channel_group broadcast;
default_type text/plain;
#default_type text/html;
}
location /bbs {
alias /opt/bbs/;
index index.html index.htm index.php;
}
location ~ ^/bbs/.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt$fastcgi_script_name;
include fastcgi_params;
#include fastcgi.conf;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
#include fastcgi.conf;
}
}
说明: 上面这个就是成功的例子。但是又如下几点需要注意:
1)location ~ \.php$ {} 段,必须放在 location ~ ^/bbs/.+\.php$ {} 段后面,否则/bbs/的url打不开
2) location ~ ^/bbs/.+\.php$ {} 里面也可以写成如下:
location ~ ^/bbs/.+\.php$ {
root /opt;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
也就是用 变量名 $document_root 代替 /opt; 其实每个 location {}中的 $document_root 都是局部变量,都是在本段配置 root指令指定的路径。
以上配置完全可以通过nginx的第3放插件 echo 模块来得到验证,方法如下:
location /echo {
root /etc/asterisk;
#echo "$document_root";
echo "$fastcgi_script_name";
}
相关文章推荐
- Nginx目录别名(Alias)支持PHP的配置
- Nginx目录别名(Alias)支持PHP的配置
- 配置Nginx来支持PHP----重点介绍Nginx如何通过PHP_FPM的FastCGI进程对PHP进行解析处理。
- nginx配置:支持phpfastcgi,nginx和php-cgi通信,部分nginx常量解释
- linux系统配置nginx支持PHP解析
- nginx配置支持PHP解析
- nginx 配置PHP fastcgi无法解析问题
- Nginx发布Alias虚拟目录及PHP支持配置方法
- 通过yum安装nginx-mysql-php-fastcgi配置LNMP
- Nginx安装配置PHP(FastCGI)环境的教程
- linux后台server开发环境的部署配置和验证(nginx+apache+php-fpm+FASTCGI(C/C++))
- Nginx防盗链、Nginx访问控制、Nginx解析php的配置
- 十二周四次课 2018.01.05 Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理
- 实战Nginx与PHP(FastCGI)的安装、配置与优化
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- iis6上配置php并且支持fastcgi
- 高性能web服务器(热死你)Resin Linux的安装、配置、部署,性能远超Nginx支持Java、PHP等
- 实战Nginx与PHP(FastCGI)的安装、配置与优化
- nginx 配置虚拟目录,并且支持PHP配置虚拟目录