Ubuntu 为什么文件可以´;是否不能通过浏览器在Nginx上打开?
我试图用以下代码隐藏最后一个斜杠:Ubuntu 为什么文件可以´;是否不能通过浏览器在Nginx上打开?,ubuntu,nginx,Ubuntu,Nginx,我试图用以下代码隐藏最后一个斜杠: rewrite ^/(.*)/$ /$1 permanent; 我这样做是为了实现这一点: example.com/file example.com/file/file2 这是因为在我的浏览器上我看到了/file,但浏览器显示页面没有正确重定向。 什么是不正确的?这是我的消息来源: 更新: index index.php index.html index.htm index.nginx-debian.html; server_name _; rewr
rewrite ^/(.*)/$ /$1 permanent;
我这样做是为了实现这一点:
example.com/file
example.com/file/file2
这是因为在我的浏览器上我看到了/file
,但浏览器显示页面没有正确重定向。
什么是不正确的?这是我的消息来源:
更新:
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
rewrite ^/(.*)/$ /$1 permanent;
rewrite ^(.*)\.php$ $1 permanent;
location / {
try_files $uri $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
欢迎来到StackOverflow!如果您在主位置块中使用try_files$uri$uri/
指令,则/file
和/file/file2
是webroot下的真实文件夹,您有一个无限重定向循环-通过try\u files
指令从/file
到/file/
,通过重写规则从/file/
到/file
。我建议您在问题中加入完整的服务器
块(当然除了真实的服务器名、证书路径等)。@IvanShatsky我只是更新了它。我正在测试,当我允许显示扩展名.php并编辑代码以重写^/(.*)/$/$1.php时;它起作用了。但是当我隐藏.php这个停止工作也是你的问题吗?@IvanShatsky Yes不能重置密码检查我最近为这个答案写的更新。它能解决你的问题吗?欢迎来到StackOverflow!如果您在主位置块中使用try_files$uri$uri/
指令,则/file
和/file/file2
是webroot下的真实文件夹,您有一个无限重定向循环-通过try\u files
指令从/file
到/file/
,通过重写规则从/file/
到/file
。我建议您在问题中加入完整的服务器
块(当然除了真实的服务器名、证书路径等)。@IvanShatsky我只是更新了它。我正在测试,当我允许显示扩展名.php并编辑代码以重写^/(.*)/$/$1.php时;它起作用了。但是当我隐藏.php这个停止工作也是你的问题吗?@IvanShatsky Yes不能重置密码检查我最近为这个答案写的更新。它能解决你的问题吗?