zoukankan      html  css  js  c++  java
  • nginx“虚拟目录”不支持php的解决办法

    这几天在配置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的绝对路径,就可以了。

  • 相关阅读:
    doc文档生成带目录的pdf文件方法
    Android uses-permission 权限大全
    AndroidManifest.xml配置文件详解 (转)
    解决导入Android例子时“Unable to resolve target 'android-x' ”的错误
    Eclipse导入Android项目的方法(转)
    数据结构与算法问题 AVL二叉平衡树
    TinyXml 与 Rapidxml效率对照
    HDU 1176-免费馅饼(DP_逆推)
    【OpenCV新手教程之十四】OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑
    交换机基础
  • 原文地址:https://www.cnblogs.com/mengdejun/p/3376390.html
Copyright © 2011-2022 走看看