Thank you very much kapono,
So with “configs” I would have to make each individual config file a separate config , then I guess I have to put all my nginx virtual host config websites into 1 file /opt/nginx/conf.d/sites.conf and map it into /etc/nginx/conf.d/sites.conf in container.
I want to keep my nginx Docker image file as simple as possible and leave the “configuration” part for docker-compose.yml so I don’t build source code into image, I would use “volumes” in docker-compose.yml. I can also use “volumes” to map nginx and php-fpm config
version: "3.3"
services:
php-fpm70:
image: php-fpm70
deploy:
replicas: 2
restart_policy:
condition: on-failure
configs:
# override php-fpm config incontainer
# My www.conf on host has "listen = 127.0.0.1:9003" , I want to change php-fpm port from 9000 #(default) to 9003
- source: www.conf.1
target: /etc/opt/rh/rh-php70/php-fpm.d/www.conf
ports:
- "9003:9003"
networks:
- webnet
web:
image: nginx
deploy:
replicas: 2
restart_policy:
condition: on-failure
configs:
- source: nginx.conf
target: /etc/nginx.conf
- source: nginx-conf.d
target: /etc/nginx/conf.d/test.conf
volumes:
- /opt/www:/opt/www
ports:
- "80:80"
- "443:443"
networks:
- webnet
configs:
nginx.conf:
file: /opt/nginx/nginx.conf
nginx-conf.d:
file: /opt/nginx/conf.d/test.conf
www.conf.1:
file: /opt/php-fpm70/www.conf
networks:
webnet:
test.conf
server {
listen 80;
server_name test.mydomain.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /opt/www/test/;
gzip on;
gzip_comp_level 9;
gzip_min_length 1000;
gzip_proxied off;
gzip_types text/plain text/css application/xml+html application/javascript image/jpeg image/x-icon image/gif image/png video/jpeg;
gzip_disable "MSIE [1-6]\.";
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
}
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 150;
fastcgi_pass 127.0.0.1:9003;
fastcgi_index index.php;
}
}
docker stack deploy -c docker-compose.yml getstartedlab
Creating config getstartedlab_nginx.conf
Creating config getstartedlab_nginx-conf.d
Creating config getstartedlab_www.conf.1
Creating service getstartedlab_php-fpm70
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ro90cgmejbzg getstartedlab_php-fpm70 replicated 2/2 php-fpm70:latest *:9003->9003/tcp
6h34rx3lpclw getstartedlab_web replicated 2/2 nginx:latest *:80->80/tcp, *:443->443/tcp
I can access to test.mydomain.com --> “Welcome to nginx” , but I cannot access test.mydomain.com/abc.php which actually show phpinfo --> “502 Bad Gateway”, here log result
docker service logs getstartedlab_web
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 10.255.0.2 - - [25/Jun/2018:02:32:44 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 2018/06/25 02:32:44 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.mydomain.com, request: "GET /nginx-logo.png HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com", referrer: "http://test.mydomain.com/"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 10.255.0.2 - - [25/Jun/2018:02:32:44 +0000] "GET /nginx-logo.png HTTP/1.1" 502 173 "http://test.mydomain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 2018/06/25 02:32:44 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.itlvn.com, request: "GET /poweredby.png HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com", referrer: "http://test.mydomain.com/"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 10.255.0.2 - - [25/Jun/2018:02:32:44 +0000] "GET /poweredby.png HTTP/1.1" 502 173 "http://test.mydomain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 2018/06/25 02:32:44 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.mydomaincom, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 10.255.0.2 - - [25/Jun/2018:02:32:44 +0000] "GET /favicon.ico HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 2018/06/25 02:32:49 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.mydomain.com, request: "GET /abc.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com"
getstartedlab_web.2.euqwfo51t392@localhost.localdomain | 10.255.0.2 - - [25/Jun/2018:02:32:49 +0000] "GET /abc.php HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
Is there something wrong with docker network so nginx container cannot connect with php-fpm70 container ?
docker network ls
NETWORK ID NAME DRIVER SCOPE
11c892f5a3ce bridge bridge local
78fb32ab0e58 docker_gwbridge bridge local
mqqwymlin3rf getstartedlab_webnet overlay swarm
270e6709c894 host host local
ojmz46usbxhh ingress overlay swarm
ffbf775e969e none null local
docker network inspect getstartedlab_webnet
[
{
"Name": "getstartedlab_webnet",
"Id": "mqqwymlin3rftfygxr2bwx4qs",
"Created": "2018-06-25T09:32:24.283490233+07:00",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.0.0/24",
"Gateway": "10.0.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"59c8fb05edd8c8ba314cc2c1f9caa81ec7181c81f4e4b917c0dbfed8e9188dd6": {
"Name": "getstartedlab_php-fpm70.2.5o4gch2n0konf5culk98hvrch",
"EndpointID": "263dc13ceb778e7a55ecf86618c0ee31efcba226c9e522e1cb530fff630dfd80",
"MacAddress": "02:42:0a:00:00:05",
"IPv4Address": "10.0.0.5/24",
"IPv6Address": ""
},
"5dde77f29ca0367bf3a589d50c41cc6c56b4e5abbb92922d7076ba28f0e18609": {
"Name": "getstartedlab_php-fpm70.1.qverc3gkt800hg944eoqomhwx",
"EndpointID": "d13a5a30425c135ed4a9deec557d0a14a9b48b9bb3bcbf2fcd67147e4bdea1c4",
"MacAddress": "02:42:0a:00:00:04",
"IPv4Address": "10.0.0.4/24",
"IPv6Address": ""
},
"c620edfe30885d16d0b0162a6591931c7b950e4b5d750eb8613555be68246ddc": {
"Name": "getstartedlab_web.1.lo33mv0xcy37j7b8bbs2lzoms",
"EndpointID": "4f2c64ceeff31c7bf37a5ed921a307af8606eed0454e04357399bf110363aa8e",
"MacAddress": "02:42:0a:00:00:07",
"IPv4Address": "10.0.0.7/24",
"IPv6Address": ""
},
"eadf040c574f8d4eecafbe53210b14a6e699bdf21236bb876f2518f5cc4fdfb5": {
"Name": "getstartedlab_web.2.euqwfo51t3925tswuicjx4w1y",
"EndpointID": "5381233c29028a51c182cc08fe1a7e667b726b5a6f3d0016e5cc5c6ea7e99ee3",
"MacAddress": "02:42:0a:00:00:08",
"IPv4Address": "10.0.0.8/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4097"
},
"Labels": {
"com.docker.stack.namespace": "getstartedlab"
},
"Peers": [
{
"Name": "80132ab1facf",
"IP": "192.168.0.124"
}
]
}
]
On host, I can see there is nginx and php-fpm containers are runnung, I cant telnet telnet 127.0.0.1 80 but cannot telnet 127.0.0.1 9003.