gpt4 book ai didi

apache - 页面加载时将 https 设置为默认值

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:31 25 4
gpt4 key购买 nike

我在 AWS EC2 上运行的 Ubuntu 16 (LTS) 服务器上运行一个网站。我在 AWS 上为我的安全组设置了以下输入规则

Type    Protocol    Port Range    Source
HTTP TCP 80 0.0.0.0/0
SSH TCP 22 72.81.131.89/32
HTTPS TCP 443 0.0.0.0/0

在我的 Ubuntu 服务器上,我已经按照描述设置了 SSL here .我还将/etc/apache2/ports.conf 编辑为以下内容。

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 8080

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
NameVirtualHost *:443
Listen 443
</IfModule>

<IfModule ssl_module>
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我没有文件/etc/apache2/sites-enabled/000-default.conf。

我创建了一个文件/etc/apache2/httpd.conf,内容如下

<VirtualHost _default_:443>
ServerName example.com:443
SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
SSLCertificateFile /etc/apache2/ssl/example.com.cert
ServerAdmin MYWEBGUY@localhost
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/errorSSL.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/accessSSL.log combined

</VirtualHost>

我已经到/etc/apache2/ssl 进入了

sudo openssl req -new -x509 -nodes -out example.com.crt -keyout example.com.key

该过程没有错误。

当我进入

sudo a2enmod ssl

我明白了

Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Module socache_shmcb already enabled
Module ssl already enabled

当我打开浏览器并输入

https://example.com

我的网页打开时带有绿色锁,表明该站点是安全的。然而,当我刚刚进入

example.com

我收到一个常规的 HTTP 连接和一条消息,指出与该站点的连接不安全。

如何在用户刚输入时让https成为默认值

example.com

最佳答案

当用户访问非 SSL 站点时,您需要强制重定向到 SSL 站点。我将添加这样的部分:

<VirtualHost *:80>
ServerName www.example.com
Redirect / https://www.example.com/
</VirtualHost>

或者更好地使用重写规则将所有请求重定向到 SSL 站点:

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

看看apache wiki了解更多信息

关于apache - 页面加载时将 https 设置为默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48732259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com