zoukankan      html  css  js  c++  java
  • Nginx目录别名(Alias)支持PHP的配置

    需求:通过 example.com 访问 /var/data/www,但通过 example.com/pa 访问的却是 /var/data/phpmyadmin,即保护phpmyadmin不暴露在www目录下。

    一、方法一:(不推荐)

    简介:这是网上普遍采用的 Rewrite 方式。
    缺陷:简单的php程序还能应付,复杂一点的程序就"No input file specified"

    server {
        listen 80;
        server_name example.com;
    
        root /var/data/www;
        index index.html index.php;
    
        location /pa {
            alias /var/data/phpmyadmin;
            index index.html index.php;
        }
    
        location ~ /pa/.+.php$ {
            rewrite /pa/(.+.php) /$1 break;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/data/phpmyadmin/$fastcgi_script_name;
            include  fastcgi_params;
        }
    
        location ~ .+.php.*$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $request_filename;
            include  fastcgi_params;
        }
    }

    二、方法二:(推荐)

    简介:完美实现,无副作用。
    特点:使用了一个叫"$valid_fastcgi_script_name"的变量

    server {
        listen 80;
        server_name example.com;
    
        root /var/data/www;
        index index.html index.php;
    
        location /pa {
            alias /var/data/phpmyadmin;
            index index.html index.php;
        }
    
        location ~ /pa/.+.php.*$ {
            if ($fastcgi_script_name ~ /pa/(.+.php.*)$) {
                set $valid_fastcgi_script_name $1;
            }
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/data/phpmyadmin/$valid_fastcgi_script_name;
            include  fastcgi_params;
        }
    
        location ~ .+.php.*$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $request_filename;
            include  fastcgi_params;
        }
    }

    二、方法三:

    简介:在 zhigang.net 上看到的创意方法,即一个站加两个server字段,然后通过反代的方式实现。
    特定:方法有创意,稍微麻烦点。

    暗夜之中,才见繁星;危机之下,暗藏转机;事在人为,为者常成。
  • 相关阅读:
    MYSQL索引使用
    事务的概念是什么,有哪些基本属性?
    springboot和springmvc的区别
    List、Map、Set的区别与联系
    MyBatis-动态SQL
    MyBatis-映射文件
    MyBatis操作数据库及全局配置文件
    Jmeter的基本使用
    MySQL索引优化
    MySQL索引
  • 原文地址:https://www.cnblogs.com/zenghansen/p/3994563.html
Copyright © 2011-2022 走看看