我不知道如何将jwilder/nginx-proxy直接连接到fastcgi后端。当我使用docker stack时,这是相应的compose文件:
php-fpm:
image: some/php-app
working_dir: /var/www/application
environment:
VIRTUAL_HOST: php-fpm.example
VIRTUAL_PROTO: fastcgi
VIRTUAL_PORT: 9000
VIRTUAL_ROOT: /var/www/application/public
此配置导致404错误:
2018/10/30 07:58:13 [error] 304: *5357 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.255.0.2, server: php-fpm.example, request: "GET /api/settings HTTP/2.0", upstream: "fastcgi://10.0.0.203:9000", host: "php-fpm.example"
如果我正确理解了情况,则缺少这样的内容:
server {
root /var/www/application/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
}
当我将此位置文件放置在/etc/nginx/vhost.d/default_location或什至/etc/nginx/vhost.d/{VIRTUAL_HOST}_location下时,我得到一个错误,提示server directive is not allowed here
。当我仅使用“位置块”时,出现502错误网关错误。
由于我有多个后端,它们几乎是相同的,所以涵盖大多数设置的一些默认配置会很棒。
有人能像这样工作吗?