配置nginx下别名alias支持PHP fastcgi解析
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支持PHP fastcgi解析的更多相关文章
- Nginx目录别名(Alias)支持PHP的配置
需求:通过 example.com 访问 /var/data/www,但通过 example.com/pa 访问的却是 /var/data/phpmyadmin,即保护phpmyadmin不暴露在ww ...
- Ubuntu配置Nginx虚拟主机和支持ThinkPHP
[Nginx配置虚拟主机] 每一个 server { listen 80; server_name www.a.com; ..... } 就表示一台虚拟域名, 然后对应的 ...
- CentOS 下用的是lnmp 的包配置Nginx 下的CI伪静态(搞爽了)
server { listen ; server_name cy.com; index index.html index.htm index.php default.html default.htm ...
- linux下别名alias的设置
我有一个常用目录/volumes/mac/www’,每次都要输入这么长的路径,麻烦,所以有了以下配置 1.vi ~/.bash_profile 2.按住shift + i进入编辑状态 3.插入 ali ...
- 配置nginx虚拟目录配置文件支持tp的pathinfo
lnmp自带的包不好用, 经测试,在相应的conf文件加入这句话即可: location / { if (!-e $request_filename) { rewrite ^(.*)$ /index. ...
- Linux上配置Nginx+PHP5(FastCGI)
原为地址:http://www.laruence.com/2009/07/28/1030.html Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,以事件驱动的方式编写,所以有非常好的性能,同时 ...
- 【解决】nginx 下$_SERVER['PATH_INFO'] 无法获取到内容
Apache是模块加载文件的,默认支持$_SERVER['PATH_INFO'] : 而对于Nginx下, 是不支持PATH INFO的, 也就是它不会默认设置PATH_INFO. 而因为Nginx默 ...
- mac设置终端命令行别名alias(git、npm)
别名(alias)通常被用作对一串或单个命令的简称.懒人必备!当常用到命令行操作的时候,每次输入一长串命令,不厌其烦,自然想到了用简称代替.这里主要介绍两种mac设置别名alias的方式. mac 设 ...
- Nginx下配置ThinkPHP的URL Rewrite模式和pathinfo模式支持
前面有关于lnmp环境的搭建,在此就不在赘述.下面就简述thinkPHP如何在nginx下开启url_rewrite和pathinfo模式支持 主要有两个步骤: 一.更改php.ini将;cgi.fi ...
随机推荐
- QQ登入(6)腾讯微博-获取微博用户信息,发送微博
1.1获取weibo用户信息 //先登入授权,可以参考QQ登入(1) Weibo mWeibo = new Weibo(this, mQQAuth.getQQToken()); mWeibo.getW ...
- HTML和JSON的数据交互-HTML模板
直接上源码,原文http://www.zhangxinxu.com/wordpress/2012/09/javascript-html-json-template/ <!DOCTYPE html ...
- HTML兼容性设置
今天碰到了兼容性问题,页面显示空白,打开调试界面,显示信息 “Compatibility View because 'Display intranet sites in Compatibility V ...
- 09-Java 工程结构管理
(一)Java 工程结构管理 1.什么是Build Path: -- 一般包括:JRE运行时库 第三方功能扩展库(*.jar 格式文件) 其他的工程 其他的源代码或Class 文件 为什么使用~ :通 ...
- es6新特性
变量-------------------------- let, const:必须直接给一个变量赋值.注意,对象的属性或数组成员还是可以改变的. const MY_OBJECT = {some: 1 ...
- paypal接口对接注意事项
追加:新的设定画面 在paypal对接过程中,会存在return_url和notify两种 分别用pdt和ipn实现 但是对于paypal,大家请注意,真实环境和沙盒测试环境的区别 你可以到www.p ...
- POJ #2479 - Maximum sum
Hi, I'm back. This is a realy classic DP problem to code. 1. You have to be crystal clear about what ...
- Linux下编译Boost
编译环境 操作系统: Red Hat Enterprise Linux Server release 5.4 64-bit 编译工具: gcc (GCC) 4.1.2 20080704 (Red Ha ...
- smartgit document merge
'Normal' Merge In case of a normal merge, a merge commit with at least two parent commits (i.e., the ...
- int long long范围
unsigned int 0-4294967295 int 2147483648-2147483647 unsigned long 0-4294967295long 2147483 ...