今天,我对NGINX有问题。
在我的NGINX配置中,我有这个:
location ~ / {
try_files $uri $uri/ /index.php?$query_string;
}
例如,我想使用使用 Laravel 定义的路由访问 https://my.domain/hello。它有效 但现在如果我访问 https://my.domain/hello/它会返回一个 404 NGINX 错误页面。我还要指出我使用Plesk。
你对如何解决这个问题有什么想法吗?
感谢您抽出宝贵时间;)
如果路径不是目录并且以/
结尾,则添加 301 重定向
if (!-d $request_filename) {
rewrite ^/(.*)/$ /$1 permanent;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
如果你检查nginx配置模板,你会发现这一行
/usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php
<?php if ($VAR->domain->physicalHosting->directoryIndex && !$VAR->domain->physicalHosting->proxySettings['nginxProxyMode']): ?>
location ~ /$ {
index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
}
<?php endif ?>
您需要重新启用代理模式(它将重新启用 apache,但 nginx 仍将首先接收请求(或为您的域创建自定义模板并删除此行
这不会与你有关,但是如果你没有使用php(例如:nodejs(,你也可以禁用php支持,这也将摆脱这一行