Configuration nginx ports 443

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

buakaw14976

New Member
Sep 20, 2024
1
0
1
Hello, i have big trouble to set up my nginx container to be allow to connect to my localhost:443, on localhost:80 everything is perfect but with 443 it's not.
i'm using docker compose here's the file :

services:
nginx:
build: ./requirements/nginx/.
container_name: nginx
ports:
- "443:443"
- "80:80"
restart: always
wordpress:
build: ./requirements/wordpress/.
container_name: wordpress
ports:
- "9000:9000"
restart: always

Here's my dockerfile :

FROM debian:bullseye-slim
RUN apt update -y && apt upgrade -y && apt install -y nginx
RUN apt install -y openssl && apt install -y vim
RUN apt install -y systemctl
COPY default /etc/nginx-available/.
COPY script.sh .
RUN bash script.sh
CMD ["bash", "script.sh"]
CMD ["nginx", "-g", "daemon off;"]

here's the server block i had to my /etc/nginx/sites-available/default nginx container :

echo "server {
listen 443 ssl;
listen [::]:443 ssl;
server_name default_server;
ssl_certificate /etc/ssl/certs/selfsigned.crt;
ssl_certificate_key /etc/ssl/private/selfsigned.key;
ssl_protocols TLSv1.3;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files / =404;
}
}

I've set my openssl certification. With docker ps i can see my nginx is using 0.0.0.0:443->443/tcp
When i writing :
lsof -i :443
lsof -i 80
I have this
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 39 root 8u IPv4 222201 0t0 TCP *:443 (LISTEN)
nginx 39 root 9u IPv6 222202 0t0 TCP *:443 (LISTEN)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 39 root 6u IPv4 222199 0t0 TCP *:80 (LISTEN)
nginx 39 root 7u IPv6 222200 0t0 TCP *:80 (LISTEN)

but when i try to localhost:443 on my google url i have a 400 bad request, i have any idea about what can be the issu
 

BackupProphet

Well-Known Member
Jul 2, 2014
1,157
732
113
Stavanger, Norway
intellistream.ai
Nginx is a typical application that do not benefit to run inside a container. Just use the nginx version that comes with your distro.
If you need to test a bleeding-edge / custom built nginx with experimental features, then a container can be useful.

The thing is, you often modify the nginx configuration files, with new proxies, modifying compression/http headers, rewrite rules, and more. Managing this with containers is just adding additional complexity for simple modifications. It is also much easier to get security updates from your distro.

If you use RHEL based distro, like Rocky or AlmaLinux you also get properly configured SELinux for free for your Nginx and PHP.

Anyway, if localhost:443 responds with 400 Bad Request, that is a good sign, it basically means Nginx is working, and the client request is bad/Unsupported.

One thing I would change though, is in /etc/nginx/sites-available/default:
Code:
server_name default_server;
with:
Code:
server_name         mydomain.example;
And then on the client pc you are using, modify /etc/hosts
Code:
192.168.1.10 mydomain.example
That may be it, but I am not sure. I installed Wordpress for a friend last year in 30 minutes, we just followed a tutorial we found on Google for RHEL. No containers.
 

slidermike

Active Member
May 7, 2023
127
50
28
This is the config example for the proxy-manager and its ports from the official documentation. Looks like using port 81 for management.

Code:
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port