本文介绍了nginx别名+位置指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

server {
    listen      80;
    server_name  pwta;
    root html;

    location /test/{
        alias html/test/;
        autoindex on;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

此配置有效.但是,如果location /test/被替换,例如location /testpath/它不起作用(未指定输入文件).根据对别名指令的解释,我假设删除了位置"部分,因此/testpath/info.php将导致html/test/info.php.

This configuration works. However, if location /test/ is replaced e.g. location /testpath/ it doesn't work (No input file specified). I assumed base on the explanation of alias directive that the "location" part is dropped and thus /testpath/info.php would result in html/test/info.php.

感谢您的任何建议.

推荐答案

nginx别名

    server {
    listen      80;
    server_name  pwta;
    index index.html index.php;
    root html;

    location /testpath/ {
        alias html/test/;
    }
    location ~  ^/testpath/(.+\.php)$ { ### This location block was the solution
        alias html/test/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$1;
        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;
        include        fastcgi_params;
    }

这篇关于nginx别名+位置指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:25