【发布时间】:2021-02-02 10:58:58
【问题描述】:
我有一个基于 webdevops/php-nginx:7.2 的 docker,我正在尝试配置 nginx 以将带有或不带有 .php 扩展名的请求路由到适当的文件。
如果abc.php 存在,我需要/abc 和/abc.php 路由到abc.php。其他一切都将转到index.php
当前设置如下:
Dockerfile 包含
WEB_DOCUMENT_ROOT=/app/public
COPY docker/opt/docker/etc /opt/docker/etc/
opt/docker/etc/nginx/conf.d/10-location-root.conf
server {
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
}
/app/public 包含
index.php
abc.php
目前,此配置将所有内容路由到 index.php,/abc.php 除外。尝试将/abc 路由到index.php。
谢谢:)
编辑:使用 Ivan 的回答 docker 记录垃圾邮件:
app_1 | -> Executing /opt/docker/bin/service.d/nginx.d//10-init.sh
app_1 | 2020-10-20 10:31:59,273 INFO success: nginxd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
app_1 | nginx: [emerg] unknown "_uri" variable
app_1 | 2020-10-20 10:31:59,287 INFO exited: nginxd (exit status 1; not expected)
【问题讨论】:
-
您能否将您当前的 PHP 处理程序配置(通常类似于
location ~ \.php$ { ... })添加到您的问题中? -
我正在使用的唯一位置处理配置是主帖中的配置 (10-location-root.conf)。如果还有其他设置,那么它可能来自 webdevops 图像:dockerfile.readthedocs.io/en/latest/content/DockerImages/… - 我是 nginx 新手,以前一直在使用 apache/htaccess,所以我不确定在哪里可以找到 php 处理程序配置的位置
-
我对 Docker 不熟悉,但是我对 nginx 很熟悉,并且了解你需要什么 nginx 配置来实现你想要的。我查看了文档,在 GitHub 上找到了 this,在我看来,您做的事情完全错了。文档提到
/opt/docker/etc/nginx/vhost.common.d/10-location-root.conf,而不是opt/docker/etc/nginx/conf.d/10-location-root.conf。我认为您的修改根本不起作用。 -
例如,使用您的
server配置,您将根本无法执行任何PHP 脚本,如果abc.php按预期工作,则意味着其他一些配置会处理它(我认为默认的)。在我看来,您至少需要修改两个文件 -/opt/docker/etc/nginx/vhost.common.d/10-location-root.conf和/opt/docker/etc/nginx/vhost.common.d/10-php.conf,也许在/opt/docker/etc/nginx/conf.d/中添加第三个自定义文件,比如说/opt/docker/etc/nginx/conf.d/maps.conf。 -
你能检查我的第一个变种吗?删除您的
/opt/docker/etc/nginx/conf.d/10-location-root.conf,将这两个文件改为并检查它是如何工作的。保持您的/app/public内容不变。
标签: docker nginx nginx-location nginx-config