Skip to content

八、Https证书配置

1、不安全的http协议

image-20220331164443240

nginx
# 6、配置证书
# 证书要放在 nginx的conf目录下

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}




http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
	
    server {
        #SSL 访问端口号为 443
        listen 443 ssl; 
        #填写绑定证书的域名
        server_name sunjiangtao.site; 
        #证书文件名称
        ssl_certificate sunjiangtao.site_bundle.crt; 
        #私钥文件名称
        ssl_certificate_key sunjiangtao.site.key; 
        ssl_session_timeout 5m;
        #请按照以下协议配置
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
        #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
        ssl_prefer_server_ciphers on;



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


    }

    server {
        listen 80;
        #填写绑定证书的域名
        server_name sunjiangtao.site; 
        #把http的域名请求转成https
        return 301 https://$host$request_uri; 
        }
    include /etc/nginx/conf.d/*.conf;
}