1、HTTPS证书:
htttps区别于http,是因为它多了加密,认证,鉴定,安全源自于非对称加密及第三方CA证书;
工作原理如下:
首先客户端生成一个随机数,发送到服务器;
服务器生成一个随机数和公钥一起发送给客户端;
客户端把数据使用公钥加密发送给服务端,服务端收到后使用私钥进行解密查看数据,建立连接。
nginx使用SSL验证,首先是需要先弄 SSL 证书才可以,付费的有很多,免费的话阿里云和腾讯云都有,下面以阿里云的为例;当然阿里也有付费的;
公司提供提供了自己的自己证书,我只需要添加即可;
然后把证书下载到本地,并上传服务器; 并放在于 ningx的配置文件的同等目录:
[root@web_01 conf.d]# mkdir /etc/nginx/conf.d/cert/
[root@web_01 conf.d]# ls /etc/nginx/conf.d/cert/
bbs.forebix.com.crt bbs.forebix.com.key
然后再当前目录下创建配置文件:内容如下:
upstream bbs.com {
#ip_hash;
server 127.0.0.1:9070;
# server 172.1.21.18:9070;
}
server {
listen 443 ssl ;
listen [::]:443 ssl ;
server_name bbs.forebix.com.com;
ssl_certificate /etc/nginx/conf.d/cert/bbs.forebix.com.com.crt;
ssl_certificate_key /etc/nginx/conf.d/cert/bbs.forebix.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
root /home/gitlab-runner/vue-static;
index index.html index.htm;
location /api {
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://bbs.com;
}
location / {
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
server {
listen 80;
server_name bbs.forebix.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
如上配置使用反向代理upstream,代理用户去本机的7090端口,而这是部署在docker里面的一个程序.
然后重新加载nginx的配置文件: nginx -t && nginx -s reload
然后在网页里https://bbs.foreb.com 即可。
[root@web_01 conf.d]# curl https://bbs.forebix.com -I
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Fri, 17 May 2019 03:53:15 GMT
Content-Type: text/html
Content-Length: 5509
Last-Modified: Wed, 15 May 2019 09:41:05 GMT
Connection: keep-alive
ETag: "5cdbdeb1-1585"
Accept-Ranges: bytes