将LAN IP的故障转移服务器添加到Nginx吗?

时间:2019-10-17 23:41:37

标签: docker nginx

我试图将计算机的LAN IP添加为“故障转移”位置,以便在主服务器出现问题时使用。

最近,由于LetsEncrypt证书问题,我的主服务器名称(即https://myserver.domain.com)遇到了一些问题,因此使用该域名在我的服务器上运行的任何URL也会失败。我想要的是让Nginx自动将其传递到计算机的IP,如果它检测到域名本身已关闭。

我正在使用Docker LinuxServer LetsEncrypt container,并且尝试将IP添加到配置中的server_name变量中,但是重新启动容器后,尝试导航时似乎没有任何变化到https://myserver.domain.com(它仍然只给出相同的错误页面,而不是重定向到IP)。

这是当前有问题的配置:

server {

    listen 443 ssl http2 default_server;

    root /config/www;
    index index.php index.html index.htm;

    server_name myserver.* 192.168.0.194:3333;

    # enable subfolder method reverse proxy confs
    include /config/nginx/proxy-confs/*.subfolder.conf;

    # Tell search engines not to crawl/add this domain
    add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    # enable for ldap auth
    #include /config/nginx/ldap.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}

请特别注意这一行;作为第二台服务器的IP是预期的故障转移IP:

server_name myserver.* 192.168.0.194:3333;

还请注意:如果我只是直接在浏览器中使用https://192.168.0.194:3333,它将导航到预期的页面,因此这必须是我要解决的Nginx配置问题。这似乎是一个非常简单的问题,但是我对Nginx配置的细微差别还不是很熟悉。

0 个答案:

没有答案