LNMP——nginx负载均衡/nginx配置ssl

11月29日

12.17 Nginx负载均衡

Nginx负载均衡

· vim /uer/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;

      peoxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;

}

}

· upstream来指定多个web server

yum install -y bind-utils

dig qq.ocm  查看qq的ip(域名解析)

/usr/local/nginx/sbin/nginx -t

/usr/loacal/nginx/sbin/nginx -s reload   检查脚本并重新加载

curl -x127.0.0.1:80 www.qq.com

Nginx不支持代理https

12.18 ssl原理

8a63c92b17222e3fc2a7babbef92d80ddd2.jpg

12.19 生成ssl密钥对

生成ssl密钥对

· cd /usr/local/nginx/conf

rpm -qf ‘which openssl’ 查看命令用哪个包安装

· openssl genrsa -des3 -out tmp.key 2048  key文件为私钥。需要输入密码

· openssl rsa -in tmp.key -out aminglinux.key 转换key,取消密码 -in指定密钥 -out指定输入

· rm -f tmp.key

· openssl req -new -key aminglinux.key -out aminglinux.csr 生成证书请求文件,需要拿这个文件和私钥一起生成公钥文件

· openssl x509 -req -days 365 -in aminglinux.csr -singkey aminglinux.key -out aminglinux.crt   -days证书日期

· 这里的aminglinux.crt为公钥

12.20 Nginx配置ssl

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

  ssl_certificate aminglinux.crt; 指定公钥

  ssl_certificate_key aminglinux.key; 指定私钥

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 指定协议

}

·/usr/local/nginx/sbin/nginx -t && -s reload 若报错unknown directive “ssl”,需要重新编译nginx,加上--with-http_ssl_module

  cd /usr/local/src/nginx-1.12.1/

· ./configure --prefix=/usr/local/nginx --with-http_ssl_module  

  make install

· mkdir /data/wwwroot/aming.com

/usr/local/nginx/sbin/nginx -t && -s reload 检查并重新加载

· echo “ssl test page.” >/data/wwwroot/aming.com/index.html

· vi /etc/hosts     编辑hosts, 增加127.0.0.1 aming.com

· curl https://aming.com/ 

 

转载于:https://my.oschina.net/u/3959687/blog/2963383

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值