1

I can not figure out, how to connect jwilder/nginx-proxy directly to a fastcgi backend. As i am using docker stack, this is the corresponding compose-file:

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

This config leads to a 404 error:

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"

If I understand the situation correctly, something like this is missing:

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; }

}

When i place this location file under /etc/nginx/vhost.d/default_location or even under /etc/nginx/vhost.d/{VIRTUAL_HOST}_location, i get a error saying server directive is not allowed here. When i only use the "location block", i get an 502 Bad Gateway Error.

Since i have multiple backends, which are mostly identical, some default config which covers most settings would be great.

Has anyone got something like this working?

user2534584
  • 483
  • 2
  • 8
  • 15
  • try this: https://stackoverflow.com/questions/41766195/nginx-emerg-server-directive-is-not-allowed-here#41766811 – codeneuss Oct 30 '18 at 08:58

0 Answers0