• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
皮特先生
博客园    首页    新随笔    联系   管理    订阅  订阅

Nginx反向代理

首先;

安装Nginx

 

vim  nginx.conf(反向代理)

 worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
     upstream default_server {
        server 192.168.184.152 weight=1;
        server 192.168.184.153 weight=1;
        }
     server {
        listen       80;
        server_name  www.yunjisuan.com;
        location / {
                proxy_pass http://default_server;
            #root   html;
            #index  index.html index.htm;
        }
}
}

[root@wangxiong conf]# /usr/local/nginx/sbin/nginx

[root@wangxiong conf]# vim /etc/hosts

[root@wangxiong html]# mkdir www
[root@wangxiong html]# ls
50x.html index.html www
[root@wangxiong html]# echo "`hostname -I` www.yunjisuan.com" > www/index.html
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 yyy.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.169 yyy.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 yyy.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.169 yyy.yunjisuan.com

然后做两个Web1和Web2服务器

安装Nginx--

步骤一样进入 Vim nginx,conf里修改

 

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr-$remote_user[$time_local]"$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
server {
listen 80;
server_name yyy.yunjisuan.com;
location / {
root html/yyy;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.yunjisuan.com;
location / {
root html/www;
index index.html index.htm;

 

}
access_log logs/access_www.log main;
}
}

[root@wangxiong conf]# /usr/local/nginx/sbin/nginx

 

[root@wangxiong conf]# cd ..
[root@wangxiong nginx]# cd html/
[root@wangxiong html]# mkdir www yyy
[root@wangxiong html]# ls
50x.html index.html www yyy
[root@wangxiong html]# echo "`hostname -I` yyy.yunjisuan.com" > yyy/index.html
[root@wangxiong html]# echo "`hostname -I` www.yunjisuan.com" > www/index.html
[root@wangxiong html]# vim /etc/hosts

[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 www.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 www.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 www.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 www.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.168 www.yunjisuan.com
[root@wangxiong html]# curl yyy.yunjisuan.com
192.168.81.168 yyy.yunjisuan.com
[root@wangxiong html]# curl yyy.yunjisuan.com
192.168.81.168 yyy.yunjisuan.com

同样;Web2也是进入Vim nginx.conf里修改配置文件

 

worker_processes 1;
events {

 

worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr-$remote_user[$time_local]"$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
server {
listen 80;
server_name yyy.yunjisuan.com;
location / {
root html/yyy;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.yunjisuan.com;
location / {
root html/www;
index index.html index.htm;

 

}
access_log logs/access_www.log main;
}
}

 

[root@wangxiong conf]# /usr/local/nginx/sbin/nginx
[root@wangxiong conf]# cd ..
[root@wangxiong nginx]# cd html/
[root@wangxiong html]# mkdir www yyy
[root@wangxiong html]# ls
50x.html index.html www yyy
[root@wangxiong html]# echo "`hostname -I` www.yunjisuan.com" > www/index.html
[root@wangxiong html]# echo "`hostname -I` yyy.yunjisuan.com" > yyy/index.html
[root@wangxiong html]# vim /etc/hosts

[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.169 www.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.169 www.yunjisuan.com
[root@wangxiong html]# curl www.yunjisuan.com
192.168.81.169 www.yunjisuan.com
[root@wangxiong html]# curl yyy.yunjisuan.com
192.168.81.169 yyy.yunjisuan.com
[root@wangxiong html]# curl yyy.yunjisuan.com
192.168.81.169 yyy.yunjisuan.com

如果在做的时候80端口拼不出来可以选择下列的方法

 

 

 

 

 

 

 

 

 

 

      

 

 

posted @ 2018-12-01 21:39  Peter,boss  阅读(342)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3