2

I'm moving some small websites in production to DDEV and, some of them has multiple domains with a 301 redirection to the main HTTPS site.

This config was working well with the "natural" Nginx when I was using a .conf file to manage the domains that should be redirect to the main site on this way:

server {
    listen 80;
    server_name     .domain1.com
            .domain2.com
            .domain3.com
    ;
    return 301 https://www.maindomain.com;
}

I tried to create a new domains.conf file and add it inside the .ddev/nginx_full directory to be loaded in the restart process but seems the Nginx didn't recognize such file.

In the main "natural" Nginx config file I has this server to redirect all requests coming from HTTP to HTTPS:

server {
        listen 80;
        access_log off;
        error_log off;
        server_name maindomain.com www.maindomain.com;
        return 301 https://www.$host$request_uri;
}

I tried to add these configs inside the .ddev/nginx_full/nginx-site.conf file but the server start to be crazy, doing sometimes infinite redirections and sometimes, not recognize the domains.

Inside the config.yaml file I have:

additional_fqdns:
- domain1.com
- domain2.com
- domain3.com
- maindomain.com
- www.maindomain.com
use_dns_when_possible: false

I'm sure that's a "right way" to handle this situation but, looking the docs, I didn't find and answer for that. On this way, I ask if someone here have the catch for that.

Thanks a lot

rfay
  • 9,963
  • 1
  • 47
  • 89
  • Remember that the `.ddev/nginx_full/.conf` is the nginx configuration for the *web container*, which is not the main termination point (which is ddev-router). I recommend that you work on this locally first, with dummy fqdns, probably that's what you're doing. If you put your nginx config into a gist on gist.github.com it will be easier for people to help you. – rfay Jun 30 '22 at 13:05

2 Answers2

0

I think this will work for you.

Add the file .ddev/nginx/redirect.conf with these contents:

    if ($http_x_forwarded_proto = "http") {
      return 301 https://$host$request_uri;
    }

This uses a DDEV nginx snippet, it could also be done with a full nginx config.

rfay
  • 9,963
  • 1
  • 47
  • 89
-1

The ddev-router acts as a reverse proxy that terminates SSL/443 and passes along requests on port 80 to the web container.

You see the infinite redirects because it sees the request always on port 80.

solitud
  • 683
  • 5
  • 15