HTTPS和FQDN重定向配置Nginx(LibreNMS)

HTTPS和FQDN重定向配置Nginx(LibreNMS),nginx,https,fqdn,Nginx,Https,Fqdn,我做了很多测试,但似乎无法得到我想要的。因此,我请你。 我有一个web应用程序(LibreNMS),它是通过CentOS 8服务器上的Nginx发布的 可通过多个主机名访问: metrontw etp.metrontw 图书馆 伦敦证券交易所 例如,当我使用不带fqdn的http攻击应用程序时http://metrontw nginx使用正确的fqdn将我重定向到https:这很好 但是 当我使用https攻击应用程序时,没有fqdn fo示例https://metrontw nginx不会重定

我做了很多测试,但似乎无法得到我想要的。因此,我请你。 我有一个web应用程序(LibreNMS),它是通过CentOS 8服务器上的Nginx发布的

可通过多个主机名访问:

metrontw etp.metrontw 图书馆 伦敦证券交易所

例如,当我使用不带fqdn的http攻击应用程序时http://metrontw nginx使用正确的fqdn将我重定向到https:这很好

但是

当我使用https攻击应用程序时,没有fqdn fo示例https://metrontw nginx不会重定向我。 怎么办

这里是我的Nginx配置文件:

## HTTP ##

server {
        listen 80;
        root        /opt/librenms/html;
        server_name etp-metrontw etp-metrontw.domain.com metrontw metrontw.domain.com;
        server_name etp-librenms etp-librenms.domain.com librenms librenms.domain.com;
        # HTTPS and FQDN redirection
        rewrite ^ https://metrontw.domain.com$request_uri?;
}

## HTTPS ##

server {
        listen 443 ssl http2;
        server_name etp-metrontw.domain.com metrontw.domain.com librenms.domain.com etp-librenms.domain.com;
        root        /opt/librenms/html;
        index       index.php;

        # Set Logs path
        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;

        # Configure SSL
        ssl_certificate /etc/nginx/ssl/librenms.pem;
        ssl_certificate_key /etc/nginx/ssl/librenms.key;

        # Enabling Gzip compression on Nginx
        charset utf-8;
        gzip on;
        gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        
        location /api/v0 {
            try_files $uri $uri/ /api_v0.php?$query_string;
        }
        
        # PHP-FPM handle all .php files requests
        location ~ \.php {
            include fastcgi.conf;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/run/php-fpm-librenms.sock;
        }
        
        location ~ /\.ht {
            deny all;
        }
 }

当我使用https和fqdn攻击应用程序时,它工作正常

非常感谢