一、环境
四台机子
1、vim /etc/hosts
192.168.40.132 web2 192.168.40.211 web1 192.168.40.155 web3 (静态)
192.168.40.129 nginx 192.168.40.200 php(动态)
2、安装httpd, 防火墙,selinux全关
3、vim /var/www/html/{index.html,index.php}
二、192.168.40.129 nginx端 配置
[root@localhost ~]# vim /etc/nginx/nginx.conf
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
upstream html {
server 192.168.40.132:80;
server 192.168.40.211:80;
server 192.168.40.155:80;
}
upstream php {
server 192.168.40.200:80;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://html;
}
location ~ \.php$ {
proxy_pass http://php;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
三、结果测试
结果如图所示
注意:apache启动不了,端口被占用情况
[root@haproxy ~]# netstat -tunlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15606/haproxy
[root@haproxy ~]# systemctl stop haproxy
[root@haproxy ~]# netstat -tunlp|grep 80
[root@haproxy ~]# systemctl restart httpd
[root@haproxy ~]# netstat -tunlp|grep 80
tcp6 0 0 :::80 :::* LISTEN 16507/httpd