nginx监听443配置https证书

解压缩下载好的证书(证书一般是pem文件和key文件,这里名字可以随便改)

将下载好的证书上上传到服务器,我将证书放在了home/ubuntu/cert文件夹中,可以写全路径

http {
    
    
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;


  server {
    
    
    #监听443端口
    listen 443;
    #你的域名
    server_name huiblog.top; 
    ssl on;
    #ssl证书的pem文件路径
    ssl_certificate  /home/ubuntu/cert/huiblog.top.pem;
    #ssl证书的key文件路径
    ssl_certificate_key /home/ubuntu/cert/huiblog.top.key;
    
    #所有请求url都转发
    location / {
    
    
     proxy_pass  http://公网地址:项目端口号;
    }
  }
  
  server {
    
    
    listen 80;
    server_name huiblog.top;
    #将请求转成https
    rewrite ^(.*)$ https://$server_name$1 permanent;
  }
}

注意:这里需要在安全组中开放443端口.

猜你喜欢

转载自blog.csdn.net/weixin_43944305/article/details/111996236
今日推荐