标签:SQ sbin 版本 code blog netstat 使用 header mys
nginx的负载均衡[root@akuilinux01 vhost]# vim load.conf
upstream qq_com
{
ip_hash;
server 111.161.64.48:80;
server 111.161.64.40: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;
}
}
[root@akuilinux01 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
ssl_certificate aminglinux.crt; #配置公钥
ssl_certificate_key aminglinux.key; #配置私钥
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #配置协议
}
[root@akuilinux01 conf]# mkdir /data/wwwroot/aming.com
[root@akuilinux01 conf]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/vhost/ssl.conf:7
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
[root@akuilinux01 ~]# cd /usr/local/src/nginx-1.14.0
[root@akuilinux01 ~]# ./configure --prefix=/usr/local/nginx --with-http_ssl_modul
[root@akuilinux01 ~]# make
[root@akuilinux01 ~]# make install
[root@akuilinux01 nginx-1.14.0]# /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@akuilinux01 ~]# /etc/init.d/nginx restart
Restarting nginx (via systemctl): [ 确定 ]
[root@akuilinux01 ~]# 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 5054/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 849/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1221/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 5054/nginx: master
tcp6 0 0 :::22 :::* LISTEN 849/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1221/master
tcp6 0 0 :::3306 :::* LISTEN 1179/mysqld
nginx监听了443端口,表示配置生效了
[root@akuilinux01 ~]# cd /data/wwwroot/aming.com/
[root@akuilinux01 aming.com]# vim index.html
this is ssl.
[root@akuilinux01 aming.com]# vim /etc/hosts
127.0.0.1 aming.com
[root@akuilinux01 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文件,使用浏览器测试
# 扩展
- [针对请求的uri来代理](http://ask.apelearn.com/question/1049)
- [根据访问的目录来区分后端的web](http://ask.apelearn.com/question/920)
- [nginx长连接](http://www.apelearn.com/bbs/thread-6545-1-1.html)
- [nginx算法分析](http://blog.sina.com.cn/s/blog_72995dcc01016msi.html)
Nginx负载均衡,ssl原理,生成ssl密钥对,Nginx配置ssl
标签:SQ sbin 版本 code blog netstat 使用 header mys
原文地址:http://blog.51cto.com/akui2521/2130451