准备工作:
3台 centos虚拟机
A机器 192.168.0.116:80
B机器 192.168.0.117:8080
C机器 192.168.0.113:8080
在A机器安装nginx,需安装依赖包,具体如下:
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
下载nginx安装包,解压后运行
./configure
make
make install
利用whereis nginx查找安装目录 /usr/local/nginx
cd sbin
开启关闭nginx
./nginx 开启
./nginx -s stop 关闭
修改配置nginx配置文件
/usr/local/nginx/conf/nginx.conf
upstream mysite {
server 192.168.0.117:8080;
server 192.168.0.113:8080;
ip_hash;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://mysite;
}
访问http://localhost或者http://192.168.0.116查看效果