1

我不知道如何将jwilder/nginx-proxy直接连接到 fastcgi 后端。当我使用 docker stack 时,这是相应的撰写文件:

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 Bad Gateway Error。

由于我有多个后端,它们大多是相同的,所以一些涵盖大多数设置的默认配置会很棒。

有没有人有这样的工作?

4

0 回答 0