I have problem with my server. I have installed NGINX, which work on port 80. I also have a php-fpm Docker container, now I need to use this php container in NGINX. How can I do this?
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c15831d9576d php:7.4-fpm "docker-php-entrypoi…" 3 seconds ago Up 2 seconds 0.0.0.0:9000->9000/tcp php
My vhost
server {
listen 80;
root /var/www/html;
server_name learn-linux.eu;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~* \.php$ {
fastcgi_pass 193.33.111.185:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
include fastcgi_params;
}
}
Testing NGINX
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
When I open my domain, I get
502 Bad gateway
My NGINX log
2020/09/22 21:02:44 [error] 2723228#2723228: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.140.255.82, server: learn-linux.eu, request: "GET / HTTP/1.1", upstream: "fastcgi://193.33.111.185:9000", host: "learn-linux.eu"
2020/09/22 21:03:46 [error] 2723228#2723228: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.140.255.82, server: learn-linux.eu, request: "GET / HTTP/1.1", upstream: "fastcgi://193.33.111.185:9000", host: "learn-linux.eu"
2020/09/22 21:03:47 [error] 2723228#2723228: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.140.255.82, server: learn-linux.eu, request: "GET / HTTP/1.1", upstream: "fastcgi://193.33.111.185:9000", host: "learn-linux.eu"
2020/09/22 21:03:47 [error] 2723228#2723228: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.140.255.82, server: learn-linux.eu, request: "GET / HTTP/1.1", upstream: "fastcgi://193.33.111.185:9000", host: "learn-linux.eu"
I tried to set php:9000, 127.0.0.1:9000, 193.33.111.185:9000 but it is still not working.
What I do wrong?