Answer the question
In order to leave comments, you need to log in
How to point nginx to php-fpm on another docker?
Made two simple dockers:
version: '3.3'
services:
nginx:
image: nginx:latest
ports:
- "6080:80"
- "543:443"
volumes:
- ./nginx/core:/etc/nginx/conf.d
- ./nginx/www:/var/www/
- ./nginx/logs:/var/log/nginx/
- ./nginx/html:/usr/share/nginx/html/
links:
- php
php:
build: ./php
container_name: php-fpm
volumes:
- ./nginx/www:/var/www
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/default.log;
error_log /var/log/nginx/default-error.log;
location / {
root /var/www/site.loc;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
2019/01/23 07:57:21 [error] 9#9: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.24.0.1, server: localhost, request: "GET / HTTP /1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:6080"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77071ee4b780 nanoninja/php-fpm:latest "docker-php-entrypoi…" About a minute ago Up About a minute 9000/tcp docker_test3_php_1
dbe3d92b037f nginx:latest "nginx -g 'daemon of…" 39 minutes ago Up 21 minutes 0.0.0.0:6080->80/tcp, 0.0.0.0:543->443/tcp docker_test2_nginx_1
Answer the question
In order to leave comments, you need to log in
Instead of
Specify
, your error indicates that nginx cannot find php-fpm at 127.0.0.1.
And this happens because the address 127.0.0.1 is an address inside the nginx container, and php-fpm lies outside it inside another container.
Due to the fact that docker-compose by default creates a network between the containers specified in the file, you can reach the service by its name from docker-compose.yml. In your case it is php
see here how to properly configure the server
phpjs.ru/2017/09/07/nginx-php-fpm-%D0%BD%D0%B0-vps...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question