标签:输入 公钥 via 原理 客户端 src issue 添加 ngui
Nginx的负载均衡[root@gary-tao ~]# yum install -y bind-utils //安装dig命令包
[root@gary-tao ~]# dig www.qq.com
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.1 <<>> www.qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5335
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.qq.com. IN A
;; ANSWER SECTION:
www.qq.com. 5 IN A 59.37.96.63
www.qq.com. 5 IN A 14.17.42.40
www.qq.com. 5 IN A 14.17.32.211
;; Query time: 6 msec
;; SERVER: 172.16.111.2#53(172.16.111.2)
;; WHEN: 五 1月 05 21:14:15 CST 2018
;; MSG SIZE rcvd: 76
[root@gary-tao ~]# cd /usr/local/nginx/conf/vhost/
[root@gary-tao vhost]# vi ld.conf
增加配置如下内容:
upstream qq_com //upstream来指定多个web server
{
ip_hash;
server 59.37.96.63;
server 14.17.42.40;
}
server
{
listen 80;
server_name www.qq.com;
location /
{
proxy_pass http://qq_com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@gary-tao vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@gary-tao vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@gary-tao vhost]# curl -x127.0.0.1:80 www.qq.com
HTTPS它是一种加密的HTTPS协议,如果HTTPS通信的数据包在传输过程中被截获,我们可以破译这些数据包里面的信息,这里面不乏一些用户名、密码、手机号等敏感的信息,而如果使用HTTPS通信,即使数据包被截获,我们也无法破译里面的内容。
[root@gary-tao ~]# cd /usr/local/nginx/conf/
[root@gary-tao conf]#
[root@gary-tao conf]# rpm -qf `which openssl` //查询缺少的openssl包,安装命令yum install -y openssl安装
openssl-1.0.2k-8.el7.x86_64
[root@gary-tao conf]# openssl genrsa -des3 -out tmp.key 2048 //生成私钥,2048为加密字符串长度,密码输入不能太短,否则不成功
Generating RSA private key, 2048 bit long modulus
.+++
..........+++
e is 65537 (0x10001)
Enter pass phrase for tmp.key:
Verifying - Enter pass phrase for tmp.key:
[root@gary-tao conf]# openssl rsa -in tmp.key -out aminglinux.key //这一步是把刚刚生成的tmp.key再转换成aminglinux.key,目的是删除刚才设置的密码,如果key文件有密码,就必须在Nginx加载它的时候输入它的密码,因此很不方便
Enter pass phrase for tmp.key:
writing RSA key
[root@gary-tao conf]# rm -f tmp.key
[root@gary-tao conf]# openssl req -new -key aminglinux.key -out aminglinux.csr //需要拿这个文件和私钥一起生产公钥文件
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [XX]:xi
State or Province Name (full name) []:tao
Locality Name (eg, city) [Default City]:xie
Organization Name (eg, company) [Default Company Ltd]:lin
Organizational Unit Name (eg, section) []:apa
Common Name (eg, your name or your server‘s hostname) []:dfd
Email Address []:adming
Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:szyino-123
An optional company name []:fdaf
[root@gary-tao conf]# openssl x509 -req -days 365 -in aminglinux.csr -signkey aminglinux.key -out aminglinux.crt //这里的aminglinux.crt为公钥。days为365是证书的日期是一年,这
Signature ok
subject=/C=xi/ST=tao/L=xie/O=lin/OU=apa/CN=dfd/emailAddress=adming
Getting Private key
[root@gary-tao conf]# vim /usr/local/nginx/conf/vhost/ssl.conf
增加如下内容:
server
{
listen 443;
server_name aming.com;
index index.html index.php;
root /data/wwwroot/aming.com;
ssl on; //开启ssl,支持https
ssl_certificate aminglinux.crt; //指定公钥
ssl_certificate_key aminglinux.key; //指定私钥
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}
[root@gary-tao conf]# mkdir /data/wwwroot/aming.com
[root@gary-tao nginx-1.12.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
指定到Nginx的源码包中,重新编译:./configure --prefix=/usr/local/nginx --with-http_ssl_module,操作如下:
[root@gary-tao conf]# cd /usr/local/src/nginx-1.12.1
[root@gary-tao nginx-1.12.1]# ./configure --help | grep -i ssl
--with-http_ssl_module enable ngx_http_ssl_module
--with-mail_ssl_module enable ngx_mail_ssl_module
--with-stream_ssl_module enable ngx_stream_ssl_module
--with-stream_ssl_preread_module enable ngx_stream_ssl_preread_module
--with-openssl=DIR set path to OpenSSL library sources
--with-openssl-opt=OPTIONS set additional build options for OpenSSL
[root@gary-tao nginx-1.12.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
[root@gary-tao nginx-1.12.1]# echo $?
0
[root@gary-tao nginx-1.12.1]# make
[root@gary-tao nginx-1.12.1]# make install
[root@gary-tao nginx-1.12.1]# /usr/local/nginx/sbin/nginx -V //现在就多了http_ssl_module这个参数 ,完成后再测试语法OK
nginx version: nginx/1.12.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
重启Nginx之后就会发现多了443的监听端口
[root@gary-tao nginx-1.12.1]# /etc/init.d/nginx restart
Restarting nginx (via systemctl): [ 确定 ]
[root@gary-tao nginx-1.12.1]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 79269/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 812/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1237/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 79269/nginx: master
tcp6 0 0 :::3306 :::* LISTEN 1166/mysqld
tcp6 0 0 :::22 :::* LISTEN 812/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1237/master
[root@gary-tao nginx-1.12.1]# cd /data/wwwroot/aming.com/
[root@gary-tao aming.com]# ls
[root@gary-tao aming.com]# vim index.html
增加如下内容:
This is ssl.
[root@gary-tao aming.com]# vi /etc/hosts
增加一条记录:127.0.0.1 aming.com
[root@gary-tao aming.com]# curl https://aming.com/
curl: (60) Peer‘s certificate issuer has been marked as not trusted by the user.
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn‘t adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you‘d like to turn off curl‘s verification of the certificate, use
the -k (or --insecure) option.
首先在要windows系统下的hosts添加解析aming.com,如果访问不了就查看下系统是否有防火墙,查看命令iptables -nvL,有的话就清空规则,命令iptables -F,也可以添加443端口的规则。
linux的Nginx负载均衡、ssl原理、生成ssl密钥对、Nginx配置ssl介绍
标签:输入 公钥 via 原理 客户端 src issue 添加 ngui
原文地址:http://blog.51cto.com/taoxie/2058801