Nginx使任何URL都可以使用或不使用尾部斜杠

时间:2017-11-11 17:06:29

标签: php url nginx server nginx-location

我希望任何目录都可以提供index.htmlindex.php - 是否提供了斜杠。

现在我的目录会在给出一个尾部斜杠 时加载,但不是没有。

# Works
localhost/mydirectory/

# Does not work
localhost/mydirectory

我只想让它以任何一种方式工作。这是我的nginx服务器块:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www;
    index index.php index.html index.htm;

    server_name localhost;

    try_files $uri $uri/ /index.php?$query_string;

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

感谢您的帮助。谢谢!

0 个答案:

没有答案
相关问题