I am trying to build three containers that are intertwined: MariaDB, Wordpress and Nginx. Right now, mariadb is functioning, and Wordpress appears to be as well, since all of its data is being put in the database. However, when I build my nginx, I get no errors, until I try to connect to wordpress by using my http://localhost or http://domain_name. It keeps saying that it is unable to connect. This is my Docker-Compose:
services:
mariadb:
container_name: mariadb
build: ./mariadb
volumes:
- mariadb_data:/var/lib/mysql
env_file:
- .env
restart: on-failure
networks:
- inception
wordpress:
container_name: wordpress
build: ./wordpress
volumes:
- wordpress_data:/var/www/html
env_file:
- .env
restart: on-failure
networks:
- inception
depends_on:
- mariadb
nginx:
container_name: nginx
build: ./nginx
restart: on-failure
networks:
- inception
depends_on:
- wordpress
volumes:
mariadb_data:
wordpress_data:
networks:
inception:
This is my Dockerfile for Nginx:
FROM debian:bullseye
EXPOSE 443
RUN apt-get update \
&& apt-get install -y \
nginx \
openssl \
&& rm -rf /var/lib/apt/lists/*
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt \
-subj "/C=PT/ST=Porto/L=Porto/O=42/OU=42/CN=ataboada.42.fr"
COPY files/nginx.conf /etc/nginx/nginx.conf
ENTRYPOINT ["nginx", "-g", "daemon off;"]
And this is my nginx-conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
ssl_protocols TLSv1.2 TLSv1.3;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name ataboada.42.fr;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
location / {
proxy_pass http://wordpress:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
obs.: it is a school assignment, so I have to use debian:bullseye as an image
You are listening to port 443 on nginx conf:
but you are not publishing that port outside of the container. You can do it like this:
Furthermore,
http://localhostmight not work unless you have redirection from http to https enabled somewhere (some browsers might do that automatically).https://localhostwill use the correct port 443.Finally, your
server_name ataboada.42.fr;block will anyway not work when using localhost, since it will only route traffic for requests tohttps://ataboada.42.fr. You can however use multiple server names in the same configuration: