2019独角兽企业重金招聘Python工程师标准>>>

​11月29日任务

12.17 Nginx负载均衡

12.18 ssl原理

12.19 生成ssl密钥对

12.20 Nginx配置ssl

12.17 Nginx负载均衡

  • vim /usr/local/nginx/conf/vhost/load.conf // 写入如下内容

upstream qq_com
{
    ip_hash;
    server 61.135.157.156:80;
    server 125.39.240.113:80;
}
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;
    }
}

  • upstream来指定多个web server

#操作过程

[root@zgxlinux-01 ~]# yum install -y bind-utils        #安装dig命令,Dig是linux中的域名解析工具。

[root@zgxlinux-01 ~]# dig qq.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49057
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;qq.com.                IN    A

;; ANSWER SECTION:
qq.com.            138    IN    A    111.161.64.48
qq.com.            138    IN    A    111.161.64.40

;; Query time: 20 msec
;; SERVER: 119.29.29.29#53(119.29.29.29)
;; WHEN: 日 12月 02 12:41:31 CST 2018
;; MSG SIZE  rcvd: 67
[root@zgxlinux-01 ~]# cd /usr/local/nginx/conf/vhost/
[root@zgxlinux-01 vhost]# vi ld.conf

[root@zgxlinux-01 vhost]# curl -x127.0.0.1:80 www.qq.com
This is the default site.
[root@zgxlinux-01 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@zgxlinux-01 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@zgxlinux-01 vhost]# curl -x127.0.0.1:80 www.qq.com      #这时候反馈的就是QQ主页的源代码

12.18 ssl原理

12.19 生成ssl密钥对

  • cd /usr/local/nginx/conf
  • openssl genrsa -des3 -out tmp.key 2048//key文件为私钥
  • openssl rsa -in tmp.key -out aminglinux.key //转换key,取消密码
  • rm -f tmp.key
  • openssl req -new -key aminglinux.key -out aminglinux.csr//生成证书请求文件,需要拿这个文件和私钥一起生产公钥文件
  • openssl x509 -req -days 365 -in aminglinux.csr -signkey aminglinux.key -out aminglinux.crt
  • 这里的aminglinux.crt为公钥

#操作过程

[root@zgxlinux-01 conf]# openssl genrsa -des3 -out tmp.key 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@zgxlinux-01 conf]# rm -f tmp.key 
[root@zgxlinux-01 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]:china
string is too long, it needs to be less than  2 bytes long
Country Name (2 letter code) [XX]:11
State or Province Name (full name) []:shanghai
Locality Name (eg, city) [Default City]:shanghai
Organization Name (eg, company) [Default Company Ltd]:zhangguoxiang
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:zhangguoxiang
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:zhangguoxiang
[root@zgxlinux-01 conf]# openssl x509 -req -days 365 -in aminglinux.csr -signkey aminglinux.key -out aminglinux.crt
Signature ok
subject=/C=11/ST=shanghai/L=shanghai/O=zhangguoxiang/CN=zhangguoxiang
Getting Private key
[root@zgxlinux-01 conf]# ls aminglinux.key 
aminglinux.key

12.20 Nginx配置ssl

  • 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_certificate aminglinux.crt;
  • ssl_certificate_key aminglinux.key;
  • ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  • }
  • -t && -s reload //若报错unknown directive “ssl” ,需要重新编译nginx,加上--with-http_ssl_module
  • mkdir /data/wwwroot/aming.com
  • echo “ssl test page.”>/data/wwwroot/aming.com/index.html
  • 编辑hosts,增加127.0.0.1 aming.com
  • curl https://aming.com/

#操作过程

[root@zgxlinux-01 conf]# cd vhost/
[root@zgxlinux-01 vhost]# vim ssl.conf

[1]+  已停止               vim ssl.conf
[root@zgxlinux-01 vhost]# mkdir /data/wwwroot/zhangguoxiang.com

[root@zgxlinux-01 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] unknown directive "erver" in /usr/local/nginx/conf/vhost/ssl.conf:2
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
[root@zgxlinux-01 vhost]# cd /usr/local/src/nginx-1.14.0/
[root@zgxlinux-01 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
[root@zgxlinux-01 nginx-1.14.0]# make && make install

[root@zgxlinux-01 nginx-1.14.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (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
[root@zgxlinux-01 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@zgxlinux-01 vhost]# /etc/init.d/nginx restart
Restarting nginx (via systemctl):                          [  确定  ]
[root@zgxlinux-01 vhost]# 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      4530/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      959/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1332/master         
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      4530/nginx: master  
tcp6       0      0 :::3306                 :::*                    LISTEN      1196/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      959/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1332/master

[root@zgxlinux-01 vhost]# cd /data/wwwroot/zhangguoxiang.com/
[root@zgxlinux-01 zhangguoxiang.com]# ls
[root@zgxlinux-01 zhangguoxiang.com]# vim 1.txt

[root@zgxlinux-01 zhangguoxiang.com]# curl -x127.0.0.1:443 https://zhangguxoiang.com
curl: (56) Received HTTP code 400 from proxy after CONNECT

[root@zgxlinux-01 zhangguoxiang.com]# vi /etc/hosts

[root@zgxlinux-01 zhangguoxiang.com]# curl https://zhangguoxiang.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.
#修改一下本机的hosts文档,添加以下内容

#清空防火墙

[root@zgxlinux-01 zhangguoxiang.com]# iptables -F

#这个时候就可以用浏览器访问,只不过我本机浏览器限制了,无法正常显示。

转载于:https://my.oschina.net/u/3959708/blog/2966414

Nginx负载均衡、ssl原理,生成ssl密钥对,配置Nginxssl相关推荐

  1. Nginx负载均衡的原理

    1.Nginx负载均衡的原理是什么? ​ 客户端向反向代理发送请求,接着反向代理根据某种负载机制转发请求至目标服务器(这些服务器都运行着相同的应用),并把获得的内容返回给客户端,期中,代理请求可能根据 ...

  2. Nginx负载均衡的原理及流程分析

    负载均衡的原理及处理流程 系统的扩展可以分为纵向扩展和横向扩展. 纵向扩展是从单机的角度出发,通过增加系统的硬件处理能力来提升服务器的处理能力 横向扩展是通过添加机器来满足大型网站服务的处理能力. 这 ...

  3. Linux centosVMware Nginx负载均衡、ssl原理、生成ssl密钥对、Nginx配置ssl

    一.Nginx负载均衡 vim /usr/local/nginx/conf/vhost/load.conf // 写入如下内容 upstream qq_com { ip_hash; 同一个用户始终保持 ...

  4. Nginx负载均衡,ssl原理,生成ssl密钥对,Nginx配置ssl

    Nginx负载均衡 负载均衡就是:将本应该这台机器(或集群)要处理的请求(工作或负载),根据一定的算法,平均地分配到其他的机器(或集群)上去处理,这样可以大大减少这台机器(或集群)的工作量,防止因负载 ...

  5. 五十、Nginx负载均衡、SSL原理、生成SSL密钥对、Nginx配置SSL

    五十.Nginx负载均衡.ssl原理.生成ssl密钥对.Nginx配置ssl 一.Nginx负载均衡 代理一台机器叫代理,代理两台机器就可以叫负载均衡. 代理服务器后有多个web服务器提供服务的时候, ...

  6. 50.Nginx负载均衡 ssl原理 密钥对 配置ssl

    2019独角兽企业重金招聘Python工程师标准>>> 12.17 Nginx负载均衡 12.18 ssl(https)原理 12.19 生成ssl密钥对 12.20 Nginx配置 ...

  7. LNMP(Nginx负载均衡,SSL原理,Nginx配置SSL,生产SSL密钥对)

    一.Nginx负载均衡 负载均衡:单从字面上的意思来理解就可以解释N台服务器平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况.那么负载均衡的前提就是要有多台服务器才能实现,也就是两台以 ...

  8. Nginx代理,Nginx负载均衡,ssl原理

    Nginx代理 Nginx代理分正向代理和反向代理. http://blog.csdn.net/zjf280441589/article/details/51501408 Nginx代理是在一台代理服 ...

  9. Nginx负载均衡与配置Nginx的ssl

    2019独角兽企业重金招聘Python工程师标准>>> Nginx负载均衡 什么是负载均衡? 负载均衡就是,把请求均衡地分发到后端的各个机器上面. 比如,A B C D 四台WEB服 ...

最新文章

  1. 深入浅出Yolov3和Yolov4
  2. 刚刚,CVPR 2021论文接收结果「开奖了」
  3. java多线程封装_Java 多线程处理任务的封装
  4. 武汉网络推广浅析当网站停止收录时该检查哪些问题?
  5. Pixhawk之姿态解算篇(5)_ECF/EKF/GD介绍
  6. MySql :Could not create connection to database server.
  7. 判断鼠标不在控件上_VB常用控件属性讲解单选按钮、复选框总结
  8. 新松机器人发行价_知识创造财富,“机器人第一股”背后的院士是怎样炼成的?...
  9. php扩展传参,c写php扩展传参学习记录
  10. 水土不服的SNS,落地生根的网游
  11. 程序流程三控制,顺序控制,分支控制,循环控制综合练习题
  12. 播放器市场瞧一瞧: 暴风影音和豪杰解霸前身后世
  13. ubuntu安装WPS字体缺失的解决办法
  14. python里的def方法中->代表什么意思
  15. 限流 Redis list 列表 Lpush rpop 实现令牌桶 – PHP 实例
  16. 图解QQ空间日志爬虫的全部日志获取与日志实际地址分析.
  17. 敏捷仪式感之:敏捷宣传栏
  18. 什么是Capability
  19. ECharts series动态加载 可执行方案
  20. 蓝桥杯 算法练习 数字游戏

热门文章

  1. boost::io模块ios相关的测试程序
  2. boost::hana::monadic_compose用法的测试程序
  3. boost::fusion::move用法的测试程序
  4. boost::fibers::buffered_channel的测试程序
  5. boost::error_info的用法测试程序
  6. Boost:std ::bind与Boost的_1绑定的测试程序
  7. Boost:与gz文件相关的操作实例
  8. VTK:可视化算法之HeadBone
  9. VTK:模型之Finance
  10. 在Eclipse中使用OpenCV Java