我是靠谱客的博主 凶狠大象,这篇文章主要介绍http请求域名强制跳转https,现在分享给大家,希望可以做个参考。

网站添加了https证书后,当http方式访问网站时就会报404错误,所以需要做http到https的强制跳转设置.

---------------一、采用nginx的rewrite方法---------------------
下面是将所有的http请求通过rewrite重写到https上。
例如将所有的www.nihao.com域名的http访问强制跳转到https。
下面配置均可以实现:

server {
    listen 80;
    server_name www.nihao.com;
    index index.html index.php index.htm;

    access_log  /usr/local/nginx/logs/8080-access.log main;
    error_log  /usr/local/nginx/logs/8080-error.log;
    
    #重点在此
    if ($host ~* "^nihao.com$") {
    rewrite ^/(.*)$ https://www.nihao.com/ permanent;
    }

    location ~ / {
        root  html;
        index index.html index.php index.htm;
    }
}

最后

以上就是凶狠大象最近收集整理的关于http请求域名强制跳转https的全部内容,更多相关http请求域名强制跳转https内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部