Nginx配置http强制跳转到https

刚刚配置好https证书,可以实现访问,可是发现个问题输入网址直接是到http网站而非https,每次需要输入https那也真麻烦

用我自己的网站实验:http:fayne.cn 直接跳转到https://fayne.cn

步骤:修改/etc/nginx/nginx.conf


server {
        listen 80;
        server_name fayne.cn;
        return 301 https://$server_name$request_uri;
}
    server {
        listen       443 default_server;
        server_name _;
        ssl on;
        ssl_certificate 1_fayne.cn_bundle.crt;
        ssl_certificate_key 2_fayne.cn.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
        ssl_prefer_server_ciphers on;
        root         /usr/share/nginx/html;
        index index.html index.php index.htm;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                root   /usr/share/nginx/html;
                index  index.html index.htm index.php;
        }
}


你可能感兴趣的:(服务器)