码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx反向代理

时间:2018-12-01 23:48:53      阅读:388      评论:0      收藏:0      [点我收藏+]

标签:etc   body   app   80端口   roo   echo   pass   status   erer   

首先;

安装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端口拼不出来可以选择下列的方法

技术分享图片

 

 

 

 

 

 

 

 

 

 

      

 

 

Nginx反向代理

标签:etc   body   app   80端口   roo   echo   pass   status   erer   

原文地址:https://www.cnblogs.com/jijiguowang/p/10051134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!