【问题标题】:nginx $document_root with subdirectories insert the subdirectory in its path带有子目录的 nginx $document_root 在其路径中插入子目录
【发布时间】:2017-08-16 04:40:56
【问题描述】:

我正在处理子目录。我想让“babylon/webmail”进入我的rainloop webmail客户端。

location ^~ /webmail {
    root /srv/rainloop/public_html;
    try_files $uri $uri/ /webmail/index.php?$query_string;
    access_log /srv/rainloop/logs/access.log;
    error_log /srv/rainloop/logs/error.log;
    index index.php;
    access_log /var/log/nginx/scripts.log scripts;

    location ~ \.php$ {
        #fastcgi_index index.php;
        #fastcgi_split_path_info ^(.+\.php)(.*)$;
        #fastcgi_keep_conn on;
        #include /etc/nginx/fastcgi_params;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        #try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME /srv/rainloop/public_html/index.php;
        #include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location ^~ /webmail/data {
        deny all;
    }
}

不过这个

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

根本不起作用。它打印出:/srv/rainloop/public_html/webmail/index.php;该文件在目录结构中不存在,但是:/srv/rainloop/public_html/index.php

fastcgi_param SCRIPT_FILENAME /srv/rainloop/public_html/index.php;

P.S.:硬编码后,我没有收到任何错误,但是页面是空白的,有一些rainloop代码源代码。

【问题讨论】:

    标签: php nginx webserver fpm


    【解决方案1】:

    文件的路径是通过将root 的值连接到URI 来计算的。 URI 包含/webmail/index.php,否则将与location 块不匹配。

    您可能的意思是使用alias 而不是root,因为该指令在计算文件路径时会删除前缀location 的值。有关详细信息,请参阅this document

    location ^~ /webmail {
        alias /srv/rainloop/public_html;
        if (!-e $request_filename) { rewrite ^ /webmail/index.php last; }
    
        ...
    
        location ~ \.php$ {
            if (!-f $request_filename) { return 404; }
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    

    由于this long term issue,请避免在同一块中使用try_filesalias,有关if 的使用请参阅this caution。使用$request_filename 作为 SCRIPT_FILENAME 值。

    【讨论】:

      猜你喜欢
      • 2014-02-15
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多