Go
beego使用Nginx服务器配置SSL证书
beego使用Nginx服务器配置SSL证书
上一篇文章跟大家分享如何将beego项目编译部署到centos,这一篇跟大家分享如何使用Nginx作为服务器配置SSL证书,开启https。
证书申请请自行解决,然后创建目录,将证书存放在/usr/local/nginx/cert/abc.cn/目录下,然后修改Nginx配置文件,并强制https,配置如下:
server { listen 80; listen 443 ssl; server_name .abc.cn; charset utf-8; access_log /home/abc.cn.access.log; #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 #error_page 404/404.html; #HTTP_TO_HTTPS_START if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } #HTTP_TO_HTTPS_END ssl_certificate /usr/local/nginx/cert/abc.cn/full_chain.pem; ssl_certificate_key /usr/local/nginx/cert/abc.cn/private.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; error_page 497 https://$host$request_uri; #SSL-END location /(css|js|fonts|img)/ { access_log off; expires 1d; root "/home/go/personForum/static"; try_files $uri @backend; } location / { try_files /_not_exists_ @backend; } location @backend { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:9090; } }
配置完之后,重启Nginx,这样就完成了配置。
0条评论