【问题标题】:Ispconfig nginx redirecting to httpsIspconfig nginx 重定向到 https
【发布时间】:2015-08-16 22:13:49
【问题描述】:

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

先谢谢了。

【问题讨论】:

    标签: redirect ssl nginx


    【解决方案1】:

    在更新版本的 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;
    

    【讨论】:

      【解决方案2】:

      我已将重定向配置为建议的接受答案。

      我还包含了一个外部配置,因此我将所有手动配置都放入了。

      在我们的 ISPConfig 版本中,我这样做了:

      if ($scheme != "https") {
        rewrite ^ https://$http_host$request_uri? permanent;
      }
      
      include /etc/nginx/sites-available/my-own-config.conf;
      

      这样,ISPConfig 不会破坏我们的配置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-24
        • 1970-01-01
        • 2020-09-11
        • 2020-03-21
        • 2016-03-10
        • 2015-02-14
        • 2019-06-04
        • 2019-08-16
        相关资源
        最近更新 更多