nginx-proxy: Cannot connect to container with fastcgi

I am having trouble getting fastcgi support to work which was introduced in #863. I am using jwilder/nginx-proxy:alpine and php:fpm-alpine images for testing and I get this error in the logs of nginx-proxy and a 404 in the browser:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

I am setting up the containers with Ansible:

- name: Pull php-fpm container
  docker_container:
    name: php-fpm
    image: php:fpm-alpine
    pull: true
    restart_policy: always
    ports:
      - "9000:9000"
    env:
      VIRTUAL_HOST: phpfpm.local
      VIRTUAL_ROOT: /var/www/html
      VIRTUAL_PORT: 9000
      VIRTUAL_PROTO: fastcgi

And the generated configuration in nginx looks like this:

# phpfpm.local
upstream phpfpm.local {
				## Can be connect with "bridge" network
			# php-fpm
			server 172.17.0.6:9000;
}
server {
	server_name phpfpm.local;
	listen 80 ;
	access_log /var/log/nginx/access.log vhost;
	include /etc/nginx/vhost.d/default;
	location / {
		root   /var/www/html;
		include fastcgi.conf;
		fastcgi_pass phpfpm.local;
	}
}

I placed a index.php with phpinfo() in /var/www/html and set permissions to www-data.

Any ideas how to debug this further?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

same issue here, i’m using this conf

version: '2'
services:
    proxy:
        image: jwilder/nginx-proxy
        ports:
            - "80:80"
        volumes:
            - /var/run/docker.sock:/tmp/docker.sock:ro

    fpm:
        image: php:fpm-alpine
        volumes:
          - ./sites:/var/www/html
        environment:
            - VIRTUAL_HOST=whoami.local
            - VIRTUAL_ROOT=/var/www/html
            - VIRTUAL_PORT=9000
            - VIRTUAL_PROTO=fastcgi

when trying access to browser, blank response, any ideas?

I’ve added this line in my custom dockerfile (FROM jwilder/nginx-proxy:alpine):

RUN echo "fastcgi_index index.php;" >> /etc/nginx/fastcgi.conf

Works but it would be good to have something like “-e VIRTUAL_INDEX=index.php”

I am facing the same issue as xgenvn:

I also met the same problem. It seems the fastcgi.conf not exists. You can try adding a fastcgi.conf in your root.

Here you can see state of container:

# docker exec -ti nginx-proxy cat /etc/nginx/fastcgi.conf
cat: /etc/nginx/fastcgi.conf: No such file or directory
# docker exec -ti nginx-proxy nginx -t
2018/03/19 11:41:25 [emerg] 56#56: open() "/etc/nginx/fastcgi.conf" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:101
nginx: [emerg] open() "/etc/nginx/fastcgi.conf" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:101
nginx: configuration file /etc/nginx/nginx.conf test failed

same issue here, i’m using this conf

version: '2'
services:
    proxy:
        image: jwilder/nginx-proxy
        ports:
            - "80:80"
        volumes:
            - /var/run/docker.sock:/tmp/docker.sock:ro

    fpm:
        image: php:fpm-alpine
        volumes:
          - ./sites:/var/www/html
        environment:
            - VIRTUAL_HOST=whoami.local
            - VIRTUAL_ROOT=/var/www/html
            - VIRTUAL_PORT=9000
            - VIRTUAL_PROTO=fastcgi

when trying access to browser, blank response, any ideas?

i have same issue, anything idea for that ?

I solved the problem by replace the file fastcgi_params to own:

fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  PATH_TRANSLATED  /$fastcgi_script_name;
fastcgi_param  HTTP_HOST        $server_name;

fastcgi_keep_conn on;
fastcgi_intercept_errors        on;
fastcgi_ignore_client_abort     off;
fastcgi_connect_timeout 100000;
fastcgi_send_timeout 100000;
fastcgi_read_timeout 100000;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

add build section to proxy docker-composer.yml:

services:
  nginx-proxy:
    build:
      context: .
      dockerfile: build.dockerfile

build.dockerfile:

FROM  jwilder/nginx-proxy:latest
COPY fastcgi_params /etc/nginx/

This is indeed my negligence caused. In my project, I added a rewrite, did not find this problem. I will consider fixing it as soon as possible.

 rewrite ^/(.*)$ /index.php?_url=/$1;

@saesh @HalisCz Hello, this bug has been resolved. See #1116

@saesh actually I’m using repo and it referenced directly from this image for the template. I checked the nginx configuration but there’re no fastcgi.conf in nginx folder. I’ll fire an issue on that repo instead 😉.

Just for completion: I added a virtual host specific location configuration file in /etc/nginx/vhost.d/phpfpm.local_location with just one line: fastcgi_index index.php; and now all works as intended. See per-virtual_host-location-configuration in the README.