网站https可以访问,https无法访问
问题的主要是两者占用端口号不同,其中https占用端口为443,http占用端口为80,出现这样问题很大可能是80端口受限。
1.检查安全组(以阿里云为例)
确保80端口在安全组中,如果没有,点击上面的快速添加按钮
完成配置后测试网站http是否能访问,如果还是不能,进入第二步。
2.检查服务器防火墙
我使用的Linux版本是 CentOS 8
检查防火墙状态
systemctl status firewalld
查看所有开放端口
firewall-cmd --zone=public --list-ports
这边是只有443端口,缺少80端口,需增加
firewall-cmd --zone=public --add-port=80/tcp --permanent
返回success后,重启防火墙
firewall-cmd --reload
当然最快的方法是直接关闭防火墙了,ememem...但并不推荐
systemctl stop firewalld
3.将http转为https
如果你使用的是nginx服务器并且有这个需求的话,只需在conf文件中添加如下代码即可(当然方法不止一种),具体的conf配置就不说了,找其他资料补充了,第一次写,希望能帮到。
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
rewrite ^(.*) https://$host$1 permanent; #http请求被80端口监听后转换为https被443端口监听
}
server {
listen 443 ssl;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate cert/7244193_www.yourdomain.com.pem;
ssl_certificate_key cert/7244193_www.yourdomain.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /pages/;
index index.html index.htm;
}
}