环境准备
主机 | 外网IP | 内网IP | 身份 |
---|---|---|---|
lb01 | 10.0.0.4 | 172.16.1.4 | 负载均衡 |
web01 | 172.16.1.7 | web服务器 | |
web03 | 172.16.1.9 | web服务器 |
配置web服务器
1)配置nginx
1 2 3 4 5 6 7 8 9 10 |
[root@web01 ~]# vim /etc/nginx/conf.d/linux.https.com.conf server { listen 80; server_name linux.https.com; location / { root /code/https; index index.html; } } |
2)配置站点
1 2 3 4 5 |
[root@web01 ~]# mkdir /code/https [root@web01 ~]# echo "web01111111" > /code/https/index.html [root@web03 ~]# mkdir /code/https [root@web03 ~]# echo "web033333333" > /code/https/index.html |
3)测试访问
1 2 3 |
[root@web01 ~]# systemctl restart nginx [root@web03 ~]# systemctl restart nginx #配置hosts访问 |
配置负载均衡服务器
1)配置nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@lb01 ~]# vim /etc/nginx/conf.d/linux.https.com.conf upstream https_web { server 172.16.1.7:80; server 172.16.1.9; } server { listen 80; server_name linux.https.com; rewrite (.*) https://linux.https.com$1; } server { listen 443 ssl; server_name linux.https.com; ssl_certificate /etc/nginx/ssl_key/server.crt; ssl_certificate_key /etc/nginx/ssl_key/server.key; location / { proxy_pass http://https_web; include proxy_params; } } |
访问页面格式错乱
2)配置后端web服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@web03 ~]# vim /etc/nginx/conf.d/linux.blog.com.conf server { listen 80; server_name linux.blog.com; root /code/wordpress; location / { index index.php; } location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #告诉PHP返回的内容要HTTPS格式的 fastcgi_param HTTPS on; include fastcgi_params; } } |