噢噢 nigix

1. 基础配置

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
       listen       80;
        server_name  project.hellowood.com;

        access_log  logs/project.access.log;

        location / {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header   Host    $host;  
                proxy_set_header   X-Real-IP   $remote_addr;   
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

访问project.hellowood.com 实际会访问该 IP 下的8080端口

2. 不同的 URL 访问不同的服务器

  • 配置 Server 节点
    server {
       listen       80;
        server_name  project.hellowood.com;

        access_log  logs/project.access.log;

        location / {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header   Host    $host;  
                proxy_set_header   X-Real-IP   $remote_addr;   
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
       listen       80;
        server_name  introduce.hellowood.com;

        access_log  logs/introduce.access.log;

        location / {
                proxy_pass http://127.0.0.1:8081;
                proxy_set_header   Host    $host;  
                proxy_set_header   X-Real-IP   $remote_addr;   
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
       listen       80;
        server_name  helloworld.com;

        access_log  logs/helloworld.access.log;

        location / {
                proxy_pass http://127.0.0.1:8082;
                proxy_set_header   Host    $host;  
                proxy_set_header   X-Real-IP   $remote_addr;   
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

访问project.hellowood.com 实际会访问该 IP 下的8080端口 
访问introduce.hellowood.com 实际会访问该 IP 下的8081端口 
访问helloworld.com 实际会访问该 IP 下的8082端口


3. 不同的项目路径访问不同的服务器

    server {  
        listen       80;  
        server_name  hellowood.com;  
        location / {  
            root   html;  
            index  index.html index.htm;  
        }  
        location /helloworld {  
            proxy_pass http://192.168.101.101:8080/helloworld;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        location /hi {  
            proxy_pass http://192.168.101.101:8080/hi;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        location /howareyou {  
            proxy_pass http://192.168.101.101:8088/howareyou;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        location /introduce {  
            proxy_pass http://10.2.10.11:9999/introduce;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  

        location /lalala {  
            proxy_pass http://www.lalala.com;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }

        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {  
            root   html;  
        }  
    }  
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

访问hellowood.com 实际会访问该 IP 下的 Nginx 目录下的静态页面 
访问hellowood.com/helloworld 实际会访问http://192.168.101.101:8080/helloworld 
访问hellowood.com/hi 实际会访问http://192.168.101.101:8080/hi 
访问hellowood.com/howareyou 实际会访问http://192.168.101.101:8088/howareyou 
访问hellowood.com/introduce 实际会访问http://10.2.10.11:9999/introduce 
访问hellowood.com/lalala 实际会访问http://www.lalala.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值