如何在Apache 2.2上禁用非SSL连接


10

我在12.04上使用Apache 2.2。我已经使用可以正常工作的自签名证书激活了ssl连接,但是现在我想禁用任何非ssl连接。

我使用 a2dissite默认值,但是80即使重新启动服务器后,仍可以在端口上访问服务器。

请帮我。

Answers:


10

我终于有了工作:

除了通过禁用默认页面: a2dissite default,我还编辑/etc/apache2/ports.conf并注释了以下几行:

NameVirtualHost *:80  
Listen 80

9

一个更好的主意是保留“非SSL连接”(http),但将其永久重定向到您的SSL虚拟主机(https)。在这种情况下,.conf文件必须看起来像:

<VirtualHost *:80>

        ServerName www.example.com
        ServerAdmin admin@example.com

        # Redirect Requests to SSL
        Redirect permanent "/" "https://www.example.com/"

        ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
        CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined

</VirtualHost>


<IfModule mod_ssl.c>

        <VirtualHost _default_:443>

                ServerName www.example.com
                ServerAdmin admin@example.com

                DocumentRoot /var/www/html/www.example.com

                ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
                CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined

                SSLEngine on

                # other configuration directives...

        </VirtualHost>

</IfModule>

相关话题:


您能否详细说明为什么不禁用HTTP是一个更好的主意?我调查禁用端口80的利弊
马可马沙拉

5
@MarcoMarsala,在大多数情况下,当禁用HTTP(端口80)并且在浏览器中键入http://your.domain.com(或只是your.domain.com)时,您将收到“找不到页面”-除非您键入https://your.domain.com...
pa4080 '18
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.