Nginx下alias支持PHP的问题解决
来源:互联网 发布:停止mysql命令 编辑:程序博客网 时间:2024/06/05 19:41
我的配置:
###文件控制程序的别名
location /webcontrols/ {
alias /data/webcontrol/scp/;
}
###对alias webcontrol下的php文件结合rewrite转交实际目录下的php文件给fastcgi处理
location ~ ^/webcontrols/.*/.php$ {
root /dat1/webcontrols/scp/;
rewrite /webcontrols/(.*/.php) /$1 break;
fastcgi_param SCRIPT_FILENAME /data/webcontrols/scp$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:10000;
fastcgi_index index.php;
}
1。官方参考
http://wiki.nginx.org/ChsFcgiExample
2。网上的一个例子
这几天在配置Nginx,PHP用FastCGI,想装一个phpMyAdmin管理数据库,phpMyAdmin不想放在网站根目录下,这样不容易和网站应用混在一起,这样phpMyAdmin的目录就放在别处,在Apache里,有alias,比较方便,在Nginx下没有虚拟目录概念的,是用location配合alias使用,我先试了简单的配置方式
location /web/ {
alias /data/web/;
index index.html index.htm index.php;
}
location ~ .*/.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
我用http://localhost/web/可以访问到/data/web目录下的静态文件,但访问php文件,却报No input file specified.的错误,而且在Nginx的error日志上却什么信息也没有,我在网上搜索了一下,判断应该是php文件并没有被后端的FastCGI运行,我又继续搜索一些文章,试着增加了一段配置
location /web/ {
alias /data/web/;
index index.html index.htm index.php;
}
location ~ ^/web/.+/.php$ {
root /data/;
rewrite /web/(.*/.php?) /$1 break;
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/web$fastcgi_script_name;
}
location ~ .*/.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
这下可以了,原理应该是采用rewrite的方法,对于/web/下php类型的的请求交给后端的FastCGI处理,并且指定了php脚本的位置,这样我们就可以配置phpMyAdmin了,配置如下
location /phpmyadmin/ {
alias /data/phpmyadmin/;
index index.html index.htm index.php;
}
location ~ ^/phpmyadmin/.+/.php$ {
root /data/;
rewrite /phpmyadmin/(.*/.php?) /$1 break;
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/phpmyadmin$fastcgi_script_name;
}
location ~ .*/.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
要注意的是
location ~ .*/.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
这段,要放在phpmyadmin的后面,放在前面就有问题,这是和Nginx的location规则有关,具体看Nginx的文档,另外,phpMyAdmin里要配置一下URI的绝对路径,就可以了。
- Nginx下alias支持PHP的问题解决
- Nginx目录别名(Alias)支持PHP的配置
- PHP(FastCGI)在Nginx的alias下404的解决方案
- Nginx发布Alias虚拟目录及PHP支持配置方法
- nginx + PHP 下 添加 https 的支持
- Linux下Nginx+PHP+Mysql安装,Nginx配置文件支持PHP
- centos下配置nginx支持php
- nginx alias 无法解析php的解决办法(附带一些nginx基本设置)
- nginx环境下配置支持php5.6(nginx+PHP)
- Nginx支持PHP的CI框架
- 让Nginx支持php的PHP_INFO
- Nginx支持php配置
- Nginx支持PHP配置
- nginx支持php配置
- 配置Nginx支持php
- Nginx支持php配置
- Nginx支持PHP配置
- Nginx支持PHP配置
- c++中system()函数的用处[转自http://blog.educity.cn/user7/50901/archives/2010/33686.html]
- nod32拦截端口
- TFS2010 权限说明
- Oralce常用SQL指令集
- vector在JAVA
- Nginx下alias支持PHP的问题解决
- sql面试题1 收藏
- .net实现远程获取其他网站页面内容
- linux常用svn命令
- hwclock: settimeofday: Invalid argument 解决
- UDP内网和外网连接通信的问题
- JS IFRAME传参
- asp.net 在 DCOM编程时需要配置的
- android NinePatchDrawable 9.png图片使用制作