标签:Nginx负载均衡 ssl原理、 生成ssl密钥对 Nginx配置ssl
一、Nginx负载均衡dig www.qq.com
curl -x127.0.0.1:80 www.qq.com
vim /usr/local/nginx/conf/vhost/load.conf // 写入如下内容
upstream qq_com //随便起个名字
{
ip_hash; //让同一个用户始终保持在同一个ip上
server 125.39.240.113:80;
server 61.135.157.156:80;
}
server
{
listen 80;
server_name www.qq.com;
location /
{
proxy_pass http://qq_com; //这里的地址是upstream
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
curl -x127.0.0.1:80 www.qq.com
这时候已经访问到qq的主页
cd /usr/local/nginx/conf
openssl genrsa -des3 -out tmp.key 2048 //key文件为私钥,这时候需要输入两次密码
openssl rsa -in tmp.key -out chinantfy.key //转换key,取消密码
rm -f tmp.key //删除带密码的key
openssl req -new -key chinantfy.key -out chinantfy.csr //生成证书请求文件,需要输入国家地区等信息,可以不填直接回车,这个文件的作用是拿这个文件和私钥一起生产公钥文件,
openssl x509 -req -days 365 -in chinantfy.csr -signkey chinantfy.key -out chinantfy.crt
vim /usr/local/nginx/conf/vhost/ssl.conf//加入如下内容
server
{
listen 443;
server_name chinantfy.com;
index index.html index.php;
root /data/wwwroot/chinantfy.com;
ssl on;
ssl_certificate chinantfy.crt;
ssl_certificate_key chinantfy.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}
/usr/local/nginx/sbin/nginx -t
配置出错,nginx少一个ssl (若报错unknown directive “ssl” ,需要重新编译nginx,加上--with-http_ssl_module)
./configure --help | grep -i ssl
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
/etc/init.d/nginx restart
mkdir /data/wwwroot/chinantfy.com
echo "ssl test page.">/data/wwwroot/chinantfy.com/index.html
编辑windows hosts文件,增加192.168.127.133(本机ip) chinantfy.com
用浏览器访问 https://chinantfy.com
如果需要浏览器认证的安全秘钥对,可以去www.wosign.com 这种网站买认证的
50.Nginx负载均衡、ssl原理、生成ssl密钥对、Nginx配置ssl
标签:Nginx负载均衡 ssl原理、 生成ssl密钥对 Nginx配置ssl
原文地址:http://blog.51cto.com/13569831/2109015