1 网关 2 机器 2 域 3 子域,如何

1 网关 2 机器 2 域 3 子域,如何

我在 nginx 中为我的一个网站设置了有效的配置,但当我尝试让它与 2 个不同的域一起工作时,它被破坏了,其中一个域有 2 个子域,它们都服务于不同的网站或应用程序。更让我头疼的是,运行 2 个应用程序的域位于不同的机器上,我试图将该域的请求代理到我的 LAN 上的正确机器。见下文:

我的建筑

我的 NGINX 配置是一场灾难,但如下:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /home/pi/sites/main;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html domain1_index.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}

server {

    root /home/pi/sites/main;

    index index.html index.htm index.nginx-debian.html;
    server_name internal.domain1.info; # managed by Certbot


    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/internal.domain1.info/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/internal.domain1.info/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



}
server {
    if ($host = internal.domain1.info) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 ;
    listen [::]:80 ;
    server_name internal.domain1.info;
    return 404; # managed by Certbot


}

server {
  server_name shiba.com www.shiba.com whispering.shiba.com;
  location / {
    proxy_pass http://<machine2'sIP>:8888;
  }
}

server {
  server_name yelling.shiba.com;
  location / {
    proxy_pass http://<machine2'sIP>:8555;
  }
}

我怎样才能让它为图片中指定的网站提供服务?谢谢。

编辑:我建议的新配置

|sites-available | symlink --> | sites-enabled
   conf1         |             |    conf1
#https website
server {
    root /home/pi/sites/main;

    index index.html index.htm index.nginx-debian.html;
    
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/internal.domain1.info/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/internal.domain1.info/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
}
#http website redirect
server {
    if ($host = internal.domain1.info) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80 ;
    listen [::]:80 ;
    server_name internal.domain1.info;
    return 404; # managed by Certbot
}
|sites-available | symlink --> | sites-enabled
   conf2         |             |    conf2
server {
    listen 80 ;
    listen [::]:80 ;
    server_name whispering.shiba.info;

    return 301 http://xxx.xxx.x.xx:8555;
}
|sites-available | symlink --> | sites-enabled
   conf3         |             |    conf3
server {
    listen 80 ;
    listen [::]:80 ;
    server_name yelling.shiba.info;

    return 301 http://xxx.xxx.x.xx:8888;
}

相关内容