Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 页面加载时将https设为默认值_Apache_Amazon Web Services_Ssl_Amazon Ec2_Https - Fatal编程技术网

Apache 页面加载时将https设为默认值

Apache 页面加载时将https设为默认值,apache,amazon-web-services,ssl,amazon-ec2,https,Apache,Amazon Web Services,Ssl,Amazon Ec2,Https,我正在运行一个网站,来自运行在AWSEC2上的Ubuntu16LTS服务器。我在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服务器

我正在运行一个网站,来自运行在AWSEC2上的Ubuntu16LTS服务器。我在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。我还对/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
这一程序没有出错

我进去的时候

sudo a2enmod ssl
我明白了

当我打开浏览器并输入

https://example.com
我的网页以绿色锁打开,表明该网站是安全的。然而,当我刚进去的时候

example.com
我得到一个常规的http连接,并收到一条消息说与该站点的连接不安全

当用户刚进入时,如何将https设置为默认值

example.com

当用户访问非SSL站点时,需要强制重定向到SSL站点。 我将添加如下一节:

<VirtualHost *:80>
   ServerName www.example.com
   Redirect / https://www.example.com/
</VirtualHost>
有关更多信息,请参阅

example.com
example.com
<VirtualHost *:80>
   ServerName www.example.com
   Redirect / https://www.example.com/
</VirtualHost>
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]