我正在为我的公司将在生产中使用的Slim Api设置php-fpm。目前我在将一个休息端点转换为可以通过php-fpm从Nginx中的代理请求执行的内容时遇到问题。
所以我在Nginx中有一个如下所示的位置块:
# endpoint that needs to be proxied
location /api2/ {
# I know, setting root in a location block is real bad
# But I am dealing with a legacy nginx config that has so much noise in it that I kinda have to do this for now.
root /path/to/api/root/index/folder;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8000;
}
所以我有一个php进程池监听端口8000,它能够运行php。我的麻烦是我在有效的api电话上继续从Slim获得404。呼叫为https://example.com/api2/get/data。
我已经能够确认,在Slim中,它接收的请求URI是/ api2 / get / data,这就是端点的定义方式。
我是否在使用Slim设置此系统时遗漏了什么?他们是一个特殊的配置,需要让Slim在Php-Fpm后面工作吗?
提前谢谢大家!
答案 0 :(得分:0)
我找到了问题的答案。看来你必须明确告诉php-fpm你通过fastcgi参数使用https!
# endpoint that needs to be proxied
location /api2/ {
# I know, setting root in a location block is real bad
# But I am dealing with a legacy nginx config that has so much noise in it that I kinda have to do this for now.
root /path/to/api/root/index/folder;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8000;
}
这解决了我遇到的所有问题。希望这可以在将来帮助其他人。
亲切,
Archerface