NGINX Docker container only sees one server block?

Please use this template for troubleshooting questions.

My issue: i have two server blocks, nginx only sees the first one.

How I encountered the problem: have first server block serving port 80 with web contents, then after issuing ssl certificate, change port to 443 and specify ssl certificate on first server block, and create second server block serving port 80 to redirect requests to https.

Solutions I’ve tried:

Version of NGINX or NGINX adjacent software (e.g. NGINX Gateway Fabric): 1.29.2

Deployment environment: Docker v26

Minimal NGINX config to reproduce your issue (preferably running on https://tech-playground.com/playgrounds/nginx for ease of debugging, and if not as a code block): (Tip → Run nginx -T to print your entire NGINX config to your terminal.)

server {
server_name example.com;
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
ssl_certificate /path/to/example.pem;
ssl_certificate_key /path/to/example-privkey.pem;
root /var/www/html;
}
server { # nginx in docker doesn't see any other server blocks besides the very first one.
server_name example.com;
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}

NGINX access/error log: (Tip → You can usually find the logs in the /var/log/nginx directory.)

okay, i’ll just self resolve this topic because this is my stupidity at best. when i change container config as a whole, i do compose up -d –-no-deps. and when i change software’s config in the container, i do docker restart or for nginx, exec nginx -s reload . kinda wish this is added in docker hub readme for nginx image, but it’s okay :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.