Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根目录中存在SSL文件夹时使用HTTPS?_Ssl_Nginx_Https_Subdomain - Fatal编程技术网

根目录中存在SSL文件夹时使用HTTPS?

根目录中存在SSL文件夹时使用HTTPS?,ssl,nginx,https,subdomain,Ssl,Nginx,Https,Subdomain,我想强制nginx中的某些子域使用HTTPS。在创建需要HTTPS的新子域时,我也不想编辑.conf文件。如果根目录中存在SSL文件夹或类似文件夹,是否可以强制使用HTTPS?所以我要做的就是在一个新的子域上启用HTTPS,添加一个新的文件夹或者类似的东西 这是我的nginx.conf文件: #HTTP DOMAIN.COM server { listen 80; server_name *.domain.

我想强制nginx中的某些子域使用HTTPS。在创建需要HTTPS的新子域时,我也不想编辑.conf文件。如果根目录中存在SSL文件夹或类似文件夹,是否可以强制使用HTTPS?所以我要做的就是在一个新的子域上启用HTTPS,添加一个新的文件夹或者类似的东西

这是我的nginx.conf文件:

    #HTTP DOMAIN.COM
    server {
       listen               80;
       server_name          *.domain.com;
       root                 /var/www/$http_host;


            location /ssl {
                    rewrite ^ https://$http_host/$1 redirect;
            }
编辑: 我一直在搞符号链接,但还没有运气。这是我做的新配置:

server {
    listen              80;
    server_name         *.domain.com;
    root                /var/www/$http_host;

        location /var/www/ssl/$http_host {
                 rewrite  https://$http_host/$1 redirect;
        }

    include             error_page;
    include             location_php;
}
我接近我的答案了吗

编辑: 我基本上想要的是能够使用ssl而不必更改我的.conf文件。
要启用HTTPS,我需要做的就是在docroot周围的某个地方更改某些内容。

我认为您不能仅基于目录的存在来启用SSL。但您可以使用文件全局绑定扩展配置:

include vhosts/*.conf
include vhosts/ssl/*.conf
只需在目录中删除一个最小的文件


(请注意,您仍然需要设置证书,最有可能是基于每个vhost的证书,并且这些证书不应包含在文档根目录中)。

我已经让它工作了!这是配置文件:

server {
    listen          80;
    server_name     *.domain.com;
    root            /var/www/$host;

    if (-e /var/www/config/ssl/$host) {
            rewrite ^ https://$host$request_uri? permanent;
    }

    include         error_pages;
    include         php_config;
}

我仍然需要使用if语句,但这没关系,因为它现在可以工作。

你能提供重定向和不重定向内容的示例URL吗?我希望sub2.domain.com是https,当我有一个ssl文件夹时,我希望能够直接转到,并且它会自动看到docroot中有一个ssl文件夹,所以它会被重定向到我一直在搜索并找到了一个关于动态SSL的某种教程(这里是链接)。它非常接近我想要的,但是他们在教程中使用if。有没有一种方法可以避免使用IF,并且仍然可以实现相同的效果?(我还不习惯使用nginx)