HTTPS其实是有两部分组成:HTTP + SSL / TLS,也就是在HTTP上又加了一层处理加密信息的模块。服务端和客户端的信息传输都会通过TLS进行加密,所以传输的数据都是加密后的数据.
首先,客户端与服务器建立连接,各自生成私钥和公钥,是不同的。服务器返给客户端一个公钥,然后客户端拿着这个公钥把要搜索的东西加密,称之为密文,并连并自己的公钥一起返回给服务器,服务器拿着自己的私钥解密密文,然后把响应到的数据用客户端的公钥加密,返回给客户端,客户端拿着自己的私钥解密密文,把数据呈现出来
docker pull nginx:latest
docker run --detach \
--name wx-nginx \
-p 443:443\
-p 80:80 \
-v /home/nginx/data:/usr/share/nginx/html:rw\
-v /home/nginx/config/nginx.conf:/etc/nginx/nginx.conf/:rw\
-v /home/nginx/config/conf.d/default.conf:/etc/nginx/conf.d/default.conf:rw\
-v /home/nginx/logs:/var/log/nginx/:rw\
-v /home/nginx/ssl:/ssl/:rw\
-d nginx
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
listen 443 ssl;
server_name localhost;
ssl_certificate /ssl/server.crt;
ssl_certificate_key /ssl/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://39.101.190.227:18080/dist/;
}
location /stmline/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://39.101.190.227:8188/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include /etc/nginx/conf.d/*.conf;
}
openssl genrsa -des3 -out server.key 2048
输入两次密码,密码自己随便定义,但是要记住,后面会用到
openssl req -new -key server.key -out server.csr
输出内容为: Enter pass phrase for root.key: ← 输入前面创建的密码
Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name)[Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ←市的全名,拼音
Organization Name (eg, company) [Internet Widgits PtyLtd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section)[]: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address[]:[email protected] ← 电子邮箱,可随意填
Please enter the following ‘extra’attributes
to be sent with your certificate request
A challengepassword []: ← 可以不输入
An optional company name []: ← 可以不输入
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
docker restart wx-nginx