1

I'm ran into an issue with Nginx and I need your help.

I've created 2 A DNS records:

www.domain_name.docker.hub.registry.domain_nameetc.com and domain_name.docker.hub.registry.domain_nameetc.com

I need both of them to return the index.html page that exists under /var/www/domain_name.docker.hub.registry/html folder.

So far when I browse to www.domain_name.docker.hub.registry.domain_nameetc.com, the index.html page appears.

When I browse to domain_name.docker.hub.registry.domain_nameetc.com, the 'Welcome to nginx' page appears.

How can I configure domain_name.docker.hub.registry.domain_nameetc.com to return the index.html page and not the standard 'Welcome to nginx' page?

Provided below is my server block code. Thank you in advance !!

server {

    root /var/www/domain_name.docker.hub.registry/html;
    index index.html;
   
    listen 80;
    listen 443 ssl;
    server_name domain_name.docker.hub.registry domain_name.docker.hub.registry.domain_nameetc.com;

    location / {
     try_files $uri $uri/ =404;
    }

    #listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/domain_name.docker.hub.registry.domain_nameetc.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain_name.docker.hub.registry.domain_nameetc.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    return 301 https://www.domain_name.docker.hub.registry.domain_nameetc.com$request_uri;
}
server {

    root /var/www/domain_name.docker.hub.registry/html;
    index index.html index.htm;

    # listen to the standard http port 80
    #listen 80;
    listen 443 ssl;

    server_name domain_name.docker.hub.registry www.domain_name.docker.hub.registry.domain_nameetc.com;

    location / {
        try_files $uri $uri/ =404;
    }

    ssl_certificate /etc/letsencrypt/live/www.domain_name.docker.hub.registry.domain_nameetc.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.domain_name.docker.hub.registry.domain_nameetc.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
3
  • Unable to replicate. Do you have other virtual hosts on this machine?
    – symcbean
    Commented Sep 8, 2023 at 13:14
  • I just have the default vhost Commented Sep 8, 2023 at 13:23
  • try removing that / replacing with an explicit named entry if required. Some versions of nginx don't handle the loading order correctly.
    – symcbean
    Commented Sep 8, 2023 at 13:26

1 Answer 1

0

I figured it out. Provided below is the solution that I went with. Please provide any feedback regarding final solution.

server {
  root /var/www/<domain>.docker.hub.registry.<domain>.com/html;
  index index.html;

  server_name <domain>.docker.hub.registry.<domain>.com;
  listen 80;
  listen [::]:80;

  location / {
   try_files $uri $uri/ =404;
  }
}

server {
  root /var/www/<domain>.docker.hub.registry.<domain>.com/html;
  index index.html;

  server_name www.<domain>.docker.hub.registry.<domain>com;
  listen 80;
  listen [::]:80;

  location / {
   try_files $uri $uri/ =404;
  }

}

server {

  root /var/www/<domain>.docker.hub.registry.<domain>.com/html;
  index index.html;

  server_name <domain>.docker.hub.registry.<domain>.com;

  listen 443 ssl;
  listen [::]:443 ssl;

  ssl_certificate /etc/letsencrypt/live/<domain>.docker.hub.registry.<domain>.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/<domain>.docker.hub.registry.<domain>.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  location / {
    try_files $uri $uri/ =404;
  }

}

server {

  root /var/www/<domain>.docker.hub.registry.<domain>.com/html;
  index index.html;

  server_name www.<domain>.docker.hub.registry.<domain>.com;

  listen 443 ssl;
  listen [::]:443 ssl;

  ssl_certificate /etc/letsencrypt/live/<domain>.docker.hub.registry.<domain>.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/<domain>.docker.hub.registry.<domain>.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  location / {
    try_files $uri $uri/ =404;
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .