0

I have next docker-compose file:

nginx:
    build: .
    ports:
        - "80:80"
        - "443:443"
    links:
        - fpm
fpm:
    image: php:fpm
    ports:
        - "9000:9000"

The Dockerfile command list is:

FROM nginx

ADD ./index.php /usr/share/nginx/html/

# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/

And my custom Nginx config default.conf file is:

server {
    listen  80;

    server_name localhost;
    root /usr/share/nginx/html;

    error_log /var/log/nginx/localhost.error.log;
    access_log /var/log/nginx/localhost.access.log;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location ~ \.php$ {
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       # With php5-cgi alone:
       fastcgi_pass 127.0.0.1:9000;
       # With php5-fpm:
       #fastcgi_pass unix:/var/run/php5-fpm.sock;
       fastcgi_index index.php;
       include fastcgi_params;
    }
}

After docker-compose up command the static pages work fine when I get http://localhost/index.html. But when I open http://localhost/index.php I had an error 502 Bad Gateway.

I think the problem with incorrect fastcgi_pass. Could anybody help me config fastcgi_pass in my case, please?

Victor Bocharsky
  • 11,930
  • 13
  • 58
  • 91
  • @IgnacioVazquez-Abrams I don't know how to connect to my runned container to get logs ( – Victor Bocharsky Apr 27 '15 at 18:20
  • 1
    did you update your php-fpm www.conf file to make sure it's not using the socket and using listen = 127.0.0.1:9000 instead? – Panama Jack Apr 27 '15 at 18:58
  • @PanamaJack I guess it should work out of the box from [php docker image](https://registry.hub.docker.com/_/php/), but I don't sure. – Victor Bocharsky Apr 27 '15 at 19:02
  • Well you can't assume anything. From looking at that it doesn't appear to change php-fpm. So you might have to update that yourself. However I'm not sure how docker works. But PHPfpm still gets it's directives from conf file. You need to also check your logs. There is no point having a server in which you are not able to check logs. It will be like find a needle in a haystack for common problems. – Panama Jack Apr 27 '15 at 19:07
  • @PanamaJack I change IP of php-fpm from local `127.0.0.1:9000` to correct `192.168.59.103:9000` because I use a boot2docker on mac. Now I see empty page (instead of "Hello Docker!"), also php-fpm throws logs in console: `172.17.42.1 - 27/Apr/2015:19:10:36 +0000 "- " 200` when get `http://localhost/index.php` page. Is there a problem with my nginx config? – Victor Bocharsky Apr 27 '15 at 19:15
  • It needs to remain 127.0.0.1 because nginx is calling it through proxypass. I don't know nigix well enough to check the config. But I use php-fpm on Apache. It still sounds like it could be in conf file. You are on a mac? – Panama Jack Apr 27 '15 at 19:24
  • What operating system are you using for nginx? – Panama Jack Apr 27 '15 at 19:24
  • @PanamaJack Yes, I'm on mac, for Nginx used debian via Docker image container. – Victor Bocharsky Apr 27 '15 at 19:26
  • 1
    I don't know nginx, but I assume `fastcgi_pass` should be the IP or name of the PHP container, *not* 127.0.0.1. You've set up a link, so fpm:9000 should work. – Adrian Mouat Apr 27 '15 at 19:43
  • are you not able to check you php-fpm config? – Panama Jack Apr 27 '15 at 19:54
  • @PanamaJack I use my work nginx config, so it should work. – Victor Bocharsky Apr 27 '15 at 19:57
  • try pointing fastcgi_pass to your docker compose service rather than 127.0.0.1 fastcgi_pass fpm:9000 – nmcilree Oct 25 '18 at 08:00

0 Answers0