Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPM not working with nginx-proxy #1035

Closed
SturmB opened this issue Jul 14, 2020 · 8 comments
Closed

FPM not working with nginx-proxy #1035

SturmB opened this issue Jul 14, 2020 · 8 comments

Comments

@SturmB
Copy link

SturmB commented Jul 14, 2020

I am attempting to get nginx-proxy to work with the php-fpm version of this via fastcgi. Unfortunately, I seem to be unable to do so. I'm sure the problem is just something simple that I don't know about.

I have boiled it down to a very simple way to re-create it. Here's my docker-compose.yml file:

version: "3"

services:
  proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    environment:
      - DEFAULT_HOST=test.local

  fpm:
    image: php:fpm
    environment:
      - VIRTUAL_HOST=test.local
      - VIRTUAL_PROTO=fastcgi

I then drop in a simple index.php file by running:

 docker container exec -it web_fpm_1 /bin/bash -c 'echo "<?php phpinfo(); ?>" > /var/www/html/index.php'

(It puts web_ in front because this project is in a directory named web/.)

I also modify my hosts file to point test.local to 127.0.0.1, so I can test it.
However, every attempt to browse to test.local results in a blank white page.

The logs for the web_fpm_1 container show that nothing gets sent except a 200 response:

[06-Jul-2020 15:40:39] NOTICE: fpm is running, pid 1
[06-Jul-2020 15:40:39] NOTICE: ready to handle connections
172.19.0.3 -  06/Jul/2020:15:41:02 +0000 "- " 200
172.19.0.3 -  06/Jul/2020:15:41:03 +0000 "- " 200

What am I doing wrong?

@tianon
Copy link
Member

tianon commented Jul 14, 2020

You'll need to use FastCGI (that container doesn't appear to do so by default); see https://github.com/nginx-proxy/nginx-proxy#fastcgi-backends

@SturmB
Copy link
Author

SturmB commented Jul 15, 2020

Isn't that what the VIRTUAL_PROTO=fastcgi environment variable is for? Does that not use FastCGI?

@tianon
Copy link
Member

tianon commented Jul 15, 2020 via email

@phy25
Copy link

phy25 commented Jul 15, 2020

Actually could you try with http://test.local/index.php directly? Not on a computer so cannot test.

@SturmB
Copy link
Author

SturmB commented Jul 15, 2020

That needs to be on your Nginx container, not the FPM container (FPM is always FastCGI).

Okay, I moved that environment variable to the nginx-proxy container. Instead of a blank white screen, I receive a 502 Bad Gateway error message.
Also, the log files for the web_fpm_1 container are empty, which tells me the proxy isn't even routing traffic to that container. It really looks like VIRTUAL_PROTO=fastcgi needs to be on the backend container, as the README document you linked specifically states.

Actually could you try with http://test.local/index.php directly? Not on a computer so cannot test.

Same results, whether the environment variable is on either container. (Blank screen when it's on the fpm container, 502 when it's on the proxy container.)

I also tried explicitly exposing port 9000, so my docker-compose.yml file now reads:

version: "3"

services:
  proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    environment:
      - DEFAULT_HOST=test.local
      - VIRTUAL_PROTO=fastcgi
      
  fpm:
    image: php:fpm
    environment:
      - VIRTUAL_HOST=test.local
    ports:
      - "9000:9000"
    expose:
      - "9000"

Same results.

When you get to a computer, you should be able to follow the steps I outlined in the original post and get the same result. If, however, it works for you, then perhaps there's something else going on in my development PC preventing it from working that I am unable to identify.

@jvasseur
Copy link

That needs to be on your Nginx container, not the FPM container (FPM is always FastCGI).

That's wrong, nginx-proxy works by inspecting containers that start/stops on the machine (that's why it needs to have access to the docker socket), thus it needs the VIRTUAL_PROTO on the fpm container to know that it should connect to the container using the fcgi protocol

@tianon
Copy link
Member

tianon commented Jul 15, 2020

Right, sorry, I misread; that was my bad.

That being said, I think this conversation is much more appropriate at https://github.com/nginx-proxy/nginx-proxy, the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

@tianon
Copy link
Member

tianon commented Jul 15, 2020

(Closing in favor of nginx-proxy/nginx-proxy#1466)

@tianon tianon closed this as completed Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants