Redirect Ispconfig nginx重定向到https

Redirect Ispconfig nginx重定向到https,redirect,ssl,nginx,Redirect,Ssl,Nginx,我已经使用ISPConfig和Nginx部署了CentOS服务器 此外,我还可以手动配置Nginx(通过编辑/etc/Nginx/sites available/mysite.com.vhost),将http请求重定向到https: server { listen 80; server_name mysite.com; return 301 https://$server_name$request_uri; } server { listen 4

我已经使用ISPConfig和Nginx部署了CentOS服务器

此外,我还可以手动配置Nginx(通过编辑/etc/Nginx/sites available/mysite.com.vhost),将http请求重定向到https:

server {
    listen 80;
    server_name mysite.com;
    return         301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    ..
}
当我手动编辑文件时,每次使用ISPConfig更改设置时,我的vhost文件都会被覆盖,并且我失去了重定向的技巧

您知道如何使用ISPConfig面板配置上述重定向,而不是手动编辑nginx文件吗


感谢avance。

在较新版本的ISPConfig上,您只需选择要使用SSL的网站(这意味着HTTPS,也可以选择SPDY或HTTP/2),并添加一个复选框,将所有HTTP请求永久重定向到HTTPS,ISPConfig将自动正确生成vhosts文件

为了完整起见,ISPConfig添加了以下内容:

server {
        listen *:80;

        listen *:443 ssl;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_certificate /var/www/clients/clientX/webY/ssl/your.web.site.crt;
        ssl_certificate_key /var/www/clients/clientX/webY/ssl/your.web.site.key;

        server_name your.web.site www.your.web.site;

        root   /var/www/your.web.site/web/;

        if ($http_host = "www.your.web.site") {
            rewrite ^ $scheme://your.web.site$request_uri? permanent;
        }
        if ($scheme != "https") {
            rewrite ^ https://$http_host$request_uri? permanent;
        }


        index index.html index.htm index.php index.cgi index.pl index.xhtml;

我已经按照公认的答案建议配置了重定向

此外,我还包括一个外部配置,所以我把所有的手动配置

在我们的ISPConfig版本中,我做到了以下几点:

if ($scheme != "https") {
  rewrite ^ https://$http_host$request_uri? permanent;
}

include /etc/nginx/sites-available/my-own-config.conf;
这样,ISPConfig就不会破坏我们的配置