一切都指向反向代理

一切都指向反向代理

我在同一台服务器上有多个域名,即IP地址,但它们都显示反向代理。

当我输入example1.com和时example2.com,它们都会转到反向代理someapp.com

这是nginx.conf文件

  # 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;
    }
  }

编辑:

当我输入时example1.com它会转到~~https~~://someapp.com

当我输入时http://example1.com它会转到example1.com

是什么赋予了?

答案1

在我看来你想https://someapp.com重定向,example1.com 转到http://example1.com然后 example2.com 就会 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; 
}

答案2

事实证明,问题出在 SSL 证书上,这意味着和都example1.com需要example2.com自己的证书。

相关内容