【发布时间】:2019-09-17 07:56:33
【问题描述】:
我正在尝试在 / 下为我的前端应用程序提供服务,但是对 /oauth2 的请求会传递给 php 后端。这是我最新的 nginx 配置尝试:
upstream dockerphp {
server backendphp:9000;
}
server {
listen 80;
server_name localhost;
index index.html;
root /application/frontend/build;
location /oauth2 {
root /application/public;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
#try_files /index.php$is_args$args =404;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass dockerphp;
fastcgi_index index.php;
}
}
location / {
try_files $uri $uri/ /index.html;
}
}
我已经尝试了几乎所有我能想到的配置组合,但无法让它发挥作用。大多数时候我都以 404 结束。
我的 nginx 和 php docker 容器都挂载了相同的 /application 目录。
使用上面的配置,任何对 /oauth2/blah 的请求都会被底部的位置块接收,因此会返回到我的前端。这可能是我最大的问题 - 我认为 /oauth2 位置块更“具体”,那为什么不是“获胜”?
我尝试了注释掉的 try_files 行(以查看 index.php 作为“后备”值是否对特异性有影响),并且 nginx 刚刚开始下载 index.php 文件而不是传递请求。帮忙?
【问题讨论】:
标签: php nginx nginx-location