Nginx-SLB部署
准备工作:
LB01:172.14.106.15
web01 :172.14.106.19
web02:172.14.106.23
-
安装nginx
yum install -y nginx
-
配置代理服务器LB01
[root@172-16-104-15 conf.d]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.104.15 hongmi.slb.com [root@172-16-104-15 conf.d]# pwd /etc/nginx/conf.d [root@172-16-104-15 conf.d]# cat slb.conf upstream slb01 { server 172.16.104.19; server 172.16.104.23; } server { listen 80; server_name hongmi.slb.com; location / { proxy_pass http://slb01; include /etc/nginx/proxy_params; } } [root@172-16-104-15 nginx]# cat nginx.conf user root; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; include /etc/nginx/conf.d/*.conf; }
-
配置后端服务器web01
[root@172-16-104-180 conf.d]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.104.15 hongmi.slb.com #本地域名解析 [root@172-16-104-180 conf.d]# cat xiaoniaoff.conf server { listen 80; server_name hongmi.slb.com; location / { root /code/xiaoniaofeifei; #访问小鸟飞飞 index index.html index.htm; } } [root@172-16-104-180 conf.d]# pwd /etc/nginx/conf.d [root@172-16-104-180 conf.d]# ls /code/xiaoniaofeifei/ #小鸟飞飞的项目位置 2000.png 21.js icon.png img index.html sound1.mp3
-
配置后端服务器web02
hongmi@worker2:/etc/nginx/conf.d$ pwd /etc/nginx/conf.d hongmi@worker2:/etc/nginx/conf.d$ cat shenjinmao.conf server { listen 80; server_name hongmi.slb.com; location / { root /code/shenjingmao; index index.html; } } root@worker2:/etc/nginx# cat nginx.conf user root; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; include /etc/nginx/conf.d/*.conf; } hongmi@worker2:/etc/nginx/conf.d$ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 worker2 172.16.104.15 hongmi.slb.com root@worker2:~# ls /code/shenjingmao/ #神经猫的项目位置 index.html static
-
访问SLB:浏览器输入hongmi.slb.com 多次刷新页面
1.神经猫
2.小鸟飞飞