12.17 Nginx负载均衡;12.18 ssl原理;12.19 生产ssl密钥对;12.20 Nginx配置ssl

简介:

扩展:

针对请求的uri来代理 http://ask.apelearn.com/question/1049

根据访问的目录来区分后端web http://ask.apelearn.com/question/920

12.17 Nginx负载均衡

1. 安装dig命令:

[root@hao-01 ~]# yum install -y bind-utils

2. 用dig获取qq.com的ip地址:

[root@hao-01 ~]# dig qq.comwKioL1mSi-bBEjX7AABZgFx33DE213.png

spacer.gif3. 创建ld.conf文件,并添加如下内容:

[root@hao-01 ~]# vi /usr/local/nginx/conf/vhost/ld.conf

添加内容(upstream指定多个web server ip):

upstream qq
{
    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;
        proxy_set_header Host   $host;
        proxy_set_header X-Real-IP      $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   

    }
}

wKioL1mSjAKCkEIoAABGEI66EQ0558.png

spacer.gif4. 检测nginx配置文件是否有错?

[root@hao-01 ~]# /usr/local/nginx/sbin/nginx -t

5. 重新加载nginx配置文件(非重启!):

[root@hao-01 ~]# /usr/local/nginx/sbin/nginx -s reload

6. curl 通过本地ip127.0.0.1访问www.qq.com,访问到了qq网站主页

[root@hao-01 ~]# curl -x127.0.0.1:80 www.qq.com

12.18 ssl原理

wKioL1mSjCLie1xqAAaVHlLlxKQ563.png

spacer.gif

12.19 生产ssl密钥对

1. 进入...conf目录下:

[root@hao-01 ~]# cd /usr/local/nginx/conf

2. 安装 openssl命令:

[root@hao-01 ~]# yum install -y which openssl

3. 当前目录下生成tmp.key私钥:

[root@hao-01 conf]# openssl genrsa -des3 -out tmp.key 2048

wKiom1mSjD_ixurBAAAjxDeXw1g394.png

spacer.gif4. 转换tmp.key私钥取消密码生成一个新的文件haosy.key私钥:

[root@hao-01 conf]# openssl rsa -in tmp.key -out haosy.key

wKiom1mSjFnS3zOyAAAX-ExObDI159.png

spacer.gif5. 删除 tmp.key私钥:

[root@hao-01 conf]# rm -f tmp.key

6. 生成证书请求文件hao.csr:

[root@hao-01 conf]# openssl req -new -key haosy.key -out hao.csr

wKiom1mSjHWi_2zkAACK_b1G9BM604.png

spacer.gif7. 生成公钥,hao.csr证书请求文件和haosy.key私钥一起生产出haogy.crt公钥:

[root@hao-01 conf]# openssl x509 -req -days 365 -in hao.csr -signkey haosy.key -out haogy.crt

wKiom1mSjI-xquPZAAAnRmHoVas417.png

spacer.gif12.20 Nginx配置ssl

1. 创建 .../hao1.com网站目录:

[root@hao-01 ~]# mkdir /data/wwwroot/hao1.com

2. 创建ssl.conf文件,并添加如下内容:

[root@hao-01 ~]# vim /usr/local/nginx/conf/vhost/ssl.conf

添加内容:

server
{
    listen 443;
    server_name hao1.com;
    index index.html index.php;
    root /data/wwwroot/hao1.com;
    ssl on;
    ssl_certificate haogy.crt;
    ssl_certificate_key haosy.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}

wKioL1mSjKuAXaGhAAAkjAxL6CI674.png

spacer.gif3. 进入nginx-1.12.1源码包目录下:

[root@hao-01 ~]# cd /usr/local/src/nginx-1.12.1/

4. 编译with-http_ssl_module :

[root@hao-01 nginx-1.12.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

5. make :

[root@hao-01 nginx-1.12.1]# make

6. make install :

[root@hao-01 nginx-1.12.1]# make install

7. 检测nginx配置文件是否有错?

[root@hao-01 ~]# /usr/local/nginx/sbin/nginx -t

8. 重启nginx服务:

[root@hao-01 nginx-1.12.1]# /etc/init.d/nginx restart

9. 查看监听端口:

[root@hao-01 nginx-1.12.1]# netstat -lntp

wKioL1mSjM6S_QrAAABFW4BYhNk507.png

spacer.gif10. 进入 .../hao1.com网站目录下:

[root@hao-01 nginx-1.12.1]# cd /data/wwwroot/hao1.com/

11.  .../hao1.com网站目录下,创建index.html测试文件添加内容

[root@hao-01 hao1.com]# vim index.html

添加内容:

This is ssl.

12. host文件中,另起一行,添加本地ip 跟指定的域名

[root@hao-01 hao1.com]# vim /etc/hosts

添加内容:

127.0.0.1 hao1.com

13. curl 访问hao1.com设定的域名网站:

[root@hao-01 hao1.com]# curl https://hao1.com

wKiom1mSjOigqvCtAABmCrHOLTM703.png

spacer.gif14. 打开windows系统找到hosts文件

路径:C:\Windows\System32\drivers\etc

wKiom1mSjQLTi5gXAAAY7XXpDSs338.png

spacer.gif15. 编辑windows下的hosts文件:

添加一条内容:

192.168.211.128 hao1.com

16. 临时关闭防火墙(不想全部清空,把443端口添加一个规则)

[root@hao-01 hao1.com]# iptables -F

17. windows下的游览器访问https://hao1.com

wKioL1mSjR6ScVl_AAAr-oY_-3s769.png










本文转自 主内安详 51CTO博客,原文链接:http://blog.51cto.com/zhuneianxiang/1956411,如需转载请自行联系原作者
相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
目录
相关文章
|
19天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
24 0
|
18天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
78 0
|
11天前
|
应用服务中间件 nginx
nginx进行反向代理的配置
在Nginx中设置反向代理的步骤:编辑`/etc/nginx/nginx.conf`,在http段加入配置,创建一个监听80端口、服务器名为example.com的虚拟主机。通过`location /`将请求代理到本地3000端口,并设置代理头。保存配置后,使用`sudo nginx -s reload`重载服务。完成配置,通过example.com访问代理服务器。
18 0
|
12天前
|
应用服务中间件 网络安全 nginx
nginx配置https访问
nginx配置https访问
25 0
|
21天前
|
应用服务中间件 nginx
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
9 0
|
22天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
18 0
|
22天前
|
应用服务中间件 nginx
nginx配置https和直接访问静态文件的方式
nginx配置https和直接访问静态文件的方式
27 3
|
23天前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
36 1
|
27天前
|
数据可视化 应用服务中间件 网络安全
简单易用的Nginx代理管理工具:体验便捷配置、高效管理
Nginx Proxy Manager是一款强大的代理服务器管理工具,提供简单直观的界面来配置和管理Nginx代理服务器,帮助用户轻松提升配置的简洁性和便捷性。
45 0
简单易用的Nginx代理管理工具:体验便捷配置、高效管理
|
29天前
|
前端开发 应用服务中间件 nginx
nginx中配置不输入端口(指定地址)访问项目的方法
nginx中配置不输入端口(指定地址)访问项目的方法
23 0