1

I have 3 sites, domain1.com, domain2.com, and domain3.com.

domain1.com has no ssl

domain2.com is just a redirect to domain1

domain3.com requires ssl

Here are my settings:

domain1.nginx

upstream domain1 {
    server localhost:3009;
}

server {
    listen 80;
    server_name www.domain1.com
    return 301 http://domain1.com$request_uri;
}

server {
    root /domain1/priv/static;
    listen 80;
    server_name domain1.com;

    location / {
        proxy_pass http://domain1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

}

domain2.nginx

server {
  server_name www.domain2.com domain2.com;
  return 301 http://domain1.com$request_uri;
}

domain3.nginx

upstream domain3 {
    server localhost:3019;
}

server {
    listen 80;
    server_name  www.domain3.com domain3.com;
    return       301 https://domain3.com$request_uri;
}

server {
    root /domain3/priv/static;
    listen 443 ssl;
    server_name domain3.com;

    ssl_certificate /etc/letsencrypt/live/domain3.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain3.com/privkey.pem;

    location / {
        proxy_pass http://domain3;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

}

What actually happens:

domain1.com works fine

www.domain2.com and domain2.com redirect to domain1.com perfectly fine

www.domain1.com redirects to domain3.com when it should just go to domain1.com

domain3.com redirects to domain1.com when it should redirect to the ssl version of domain3.com

www.domain3.com redirects to the ssl version of domain3.com fine

What am I doing wrong?

Here's a gist with some slightly different settings, but has the same issue: https://gist.github.com/anonymous/6ba8865593c7c3e57f2035bafa3105b7

  • Please post the output of nginx -t. – Michael Hampton Oct 9 '16 at 16:42
  • @MichaelHampton nginx: [warn] server name "http://domain1.com$request_uri" has suspicious symbols in /etc/nginx/sites-enabled/domain1.nginx:8 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful – Magnus Oct 10 '16 at 1:50
  • Now look at that line and the previous line. – Michael Hampton Oct 10 '16 at 2:02
  • @MichaelHampton Here is the complete output of nginx -T gist.github.com/anonymous/6ba8865593c7c3e57f2035bafa3105b7 – Magnus Oct 10 '16 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.