ispconfig nginx 重定向到https

Ispconfig nginx redirecting to https

我已经使用 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 文件吗?

提前致谢。

在较新版本的 ISPConfig 上,您可以简单地 select 使用 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 就不会破坏我们的配置。