0

I have several domains on the same server i.e IP address, but they all show the reverse proxy.

When I type in example1.com and example2.com, they both go to the reverse proxy for someapp.com

Here's the nginx.conf file

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

  server {
    listen 443 ssl;

    server_name someapp.com;

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

    location / {
      proxy_pass 'http://localhost:3000/';
    }

    location /pics/ {
      root /home/user;
      try_files $uri $uri/ =404;
    }
  }

  # example1.com ######################################

  server {
    listen 80;
    server_name example1.com;
    location / {
       proxy_pass 'http://127.0.0.1:5000';
    }
  }

  # example2.com ######################################

  server {
    listen 80;
    server_name example2.com;
    root /home/user/example2;
    index index.html;
    location / {
        try_files $uri $uri/ =404;
    }
  }

EDIT:

When I type example1.com it goes to ~~https~~://someapp.com

When I type http://example1.com it goes to example1.com

What gives?

0

in my mind you want to https://someapp.com redirection , example1.com go to http://example1.com and example2.com goes http://example2.com

#Someapp.com
server {
   server_name someapp.com;
   location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
   }
   location /pics/ {
      root /home/user;
      try_files $uri $uri/ =404;
    }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/someapp.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/someapp.com/privkey.pem;

}
# example1.com ######################################
server {
    listen 80;
    server_name example1.com;
    location / {
       proxy_pass 'http://127.0.0.1:5000';
       proxy_http_version 1.1;
       proxy_set_header Host $host;
   }
}

# example2.com ######################################
server {
    listen 80;
    server_name example2.com;
    root /home/user/example2;
    index index.html;
    location / {
        try_files $uri $uri/ =404;
    }
}

#someapp.com - Redirection
server {
    if ($host = someapp.com) {
    #rewrite ^/(.*)$ https://$host/$1 permanent;
        return 301 https://$host$request_uri;
    } 
server_name someapp.com;
    listen 80;
    return 404; 
}
-1

Turns out the problem was due to the SSL certificate, meaning both example1.com and example2.com need their own certificates.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.