本文共 4771 字,大约阅读时间需要 15 分钟。
[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.confserver{listen 443;server_name aming.com;index index.html index.php;root /data/wwwroot/aming.com;ssl on; #开启sslssl_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 -tnginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/vhost/ssl.conf:7nginx: 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 -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@akuilinux01 ~]# /etc/init.d/nginx restartRestarting nginx (via systemctl): [ 确定 ][root@akuilinux01 ~]# netstat -lntpActive 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.htmlthis is ssl.[root@akuilinux01 aming.com]# vim /etc/hosts127.0.0.1 aming.com[root@akuilinux01 aming.com]# curl https://aming.comcurl: (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 defaultbundle file isn't adequate, you can specify an alternate fileusing the --cacert option.If this HTTPS server uses a certificate signed by a CA represented inthe bundle, the certificate verification probably failed due to aproblem with the certificate (it might be expired, or the name mightnot match the domain name in the URL).If you'd like to turn off curl's verification of the certificate, usethe -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)
转载于:https://blog.51cto.com/akui2521/2130451