下载地址
参考博客
openssl version -a
可以使用Xshell的Xftp工具。
tar -zxvf openssl-1.1.1-pre8.tar.gz
#如果系统安装了gcc编译器,如下图所示的gcc version
gcc -v
#安装gcc
yum install gcc-c++
#检查是否安装zlib,如果安装如下图所示
whereis zlib
#获取zlib源码包
wget http://zlib.net/zlib-1.2.11.tar.gz
#切换到zlib源码包中
cd zlib-1.2.11
#安装zlib
./configure && make && make install
#首先进入OpenSSL工具解压之后的目录
cd openssl-1.1.1-pre8
#--prefix=指定的安装路径
./config shared zlib --prefix=/usr/local/openssl && make && make install
#安装完成之后再当前目录再执行下面命令
./config -t make depend
#然后进入OpenSSL的安装目录
cd /usr/local
#建立文件链接
ln -s openssl ssl
#打开etc下的这个ld.so.conf配置文件,然后再文本中添加/usr/local/openssl/lib
vim /etc/ld.so.conf
#执行命令使文件链接共享生效
ldconfig
#打开etc目录下的profile文件
vim /etc/profile
#然后再文件的末尾添加如下内容
export OPENSSL=/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
参考博客
#生成私钥到指定目录
openssl genrsa -out /usr/local/nginx/conf/rootca.key
#通过私钥生成申请文件到指定目录
openssl req -new -key /usr/local/nginx/conf/rootca.key -out /usr/local/nginx/conf/rootca.csr
#通过私钥和证书申请文件,来自签证书
openssl x509 -req -days 3650 -in /usr/local/nginx/conf/rootca.csr -signkey /usr/local/nginx/conf/rootca.key -out /usr/local/nginx/conf/rootca.crt
#生成服务端私钥
openssl genrsa -out /usr/local/nginx/conf/server.key
#生成服务端证书申请文件
openssl req -new -key /usr/local/nginx/conf/server.key -out /usr/local/nginx/conf/server.csr
#签发服务端证书文件
openssl ca -in /usr/local/nginx/conf/server.csr -cert /usr/local/nginx/conf/rootca.crt -keyfile /usr/local/nginx/conf/rootca.key -out /usr/local/nginx/conf/server.crt
参考博客
#通过wget命令来远程获取源码包到当前目录
wget http://nginx.org/download/nginx-1.15.2.tar.gz ./
#通过wget命令来远程获取源码包到当前目录
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz ./
#解压压缩包
tar -zxvf pcre-8.40.tar.gz
#切换到解压的目录中
cd ./pcre-8.40
#安装
./configure && make && make install
#解压压缩包
tar -zxvf nginx-1.15.2.tar.gz
#切换到解压的目录中
cd ./nginx-1.15.2
#安装
./configure && make && make install
参考博客
#备份配置文件,前面是文件名,后面携带备份时间
cp nginx.conf ./nginx.conf.2018816
#备份安装目录sbin中 nginx运行文件
cp ./nginx/sbin/nginx ./nginx/sbin/nginx2018816
#备份安装目录sbin中 nginx运行文件
cp ./nginx/sbin/nginx ./nginx/sbin/nginx2018816
#先cd到源码包中
#获取https模块到指定目录
./configure --prefix=./nginx --with-http_stub_status_module --with-http_ssl_module
#编译
make
#将编译好的nginx运行文件复制到安装目录的sbin中
cp ./objs/nginx /usr/local/nginx/sbin/
#通过命令查看Https模块是否安装成功,如果安装成功如下图所示
/usr/local/nginx/sbin/nginx -V
#测试nginx.conf文件是否配置正确
./sbin/nginx -t
#启动nginx
./sbin/nginx
#重启
./sbin/nginx -s reload
访问Nginx部署的服务器ip地址,出现如下图所示页面则表示安装成功。
listen 443 ssl;
server_name 10.3.1.2;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/openssl/bin/nopass-server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
server_tokens off;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location = /xxx {
return 302 http://10.3.1.2:18080/bms_core;
}
location = /bms_core/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.3.1.1:18080;
}
location ~ \.(gif|jpg|png|js|css)$ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.3.1.1:18080;
}
server {
listen 80;
server_name 10.3.1.2;
location / {
root html;
index index.html index.htm;
}
location = /bms_core/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_pass http://10.3.1.1:18080;
#return 302 http://10.3.1.2:18080/bms_core;
}
location ~ \.(gif|jpg|png|js|css)$ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.3.1.1:18080;
}
location = /bms {
return 302 http://10.3.1.2:18080/bms_core;
}
}
worker_processes 4;
events {
worker_connections 1024;
}
http {
include 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 /usr/local/nginx/logs/access.log main;
sendfile on;
keepalive_timeout 65;
upstream my_server{
server 10.3.1.2:3128 weight=5 ;
server 10.3.1.2:80 weight=1;
}
server {
listen 80;
server_name 10.3.1.2;
location / {
root html;
index index.html index.htm;
}
location = /bms_core/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_pass http://10.3.1.1:18080;
#return 302 http://10.3.1.2:18080/bms_core;
}
location ~ \.(gif|jpg|png|js|css)$ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.3.1.1:18080;
}
location = /bms {
return 302 http://10.3.1.2:18080/bms_core;
}
}
server {
listen 443 ssl;
server_name 10.3.1.2;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/openssl/bin/nopass-server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
server_tokens off;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
location = /xxx {
return 302 http://10.3.1.2:18080/bms_core;
}
location = /bms_core/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.3.1.1:18080;
}
location ~ \.(gif|jpg|png|js|css)$ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.3.1.1:18080;
}
}
}
Https参考博客
SSL/TLS握手参考博客
收费证书申请推荐
免费证书签发机构参考博客
参考博客
#查看网卡名命令
ifconfig
#通过tcpdump抓包
#eth0为网卡名
#host 10.2.1.254为发起请求的客户端ip地址
#-w ./eth1.cap是将抓包信息输出到指定目录下指定文件中
tcpdump -i eth0 host 10.2.1.254 -w ./eth1.cap
参考博客
在Wireshark中点击文件,然后打开抓包文件。
点击请求,然后右键追踪TCP流。
通过Client向服务端发起的Http请求看到,客户端向服务端发起Http请求,并且通过追踪TCP流可以看到数据是明文传输没有被加密。
通过Client向服务端发起的Https请求看到,中间建立了TLS握手,并且通过追踪TCP流可以看到数据是使用对称加密后的数据。