nginx的三种反向代理方式你都知道么


本文摘自PHP中文网,作者V,侵删。

nginx反向代理的三种模式分别是:

1、基于IP代理

2、基于域名代理

3、基于端口代理

(相关教程推荐:nginx教程)

nginx.conf

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

worker_processes  1;

 

events {

    worker_connections  1024;

}

 

http {

    charset utf-8;

    include       mime.types;

    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    # log_format  main  'remote_addr=$remote_addr:$remote_port, http_x_forwarded_for=$http_x_forwarded_for, proxy_add_x_forwarded_for=$proxy_add_x_forwarded_for ';

    access_log  logs/access_format.log  main;

 

    sendfile        on;

    #tcp_nopush     on;

 

    #keepalive_timeout  0;

    keepalive_timeout  65;

 

    #gzip  on

     

    # 原始server

    server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;

            index  index.html index.htm;

        }

    }

    # 引入自定义的server配置

    include my-proxy-server.conf;

}

my-proxy-server.conf

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

57

58

59

########################################################################

# 基于端口代理

########################################################################

server {

    listen       81;

    server_name  localhost;

    location / {

        proxy_pass http://192.168.0.153:9091;

        proxy_redirect default;

    }

    location = /50x.html {

        root   html;

    }

}

server {

    listen       82;

    server_name  localhost;

    location / {

        proxy_pass http://git.itplh.com;

        proxy_redirect default;

    }

    location = /50x.html {

        root   html;

    }

}

 

########################################################################

# 基于域名代理 + gitlocal负载均衡

########################################################################

upstream gitlocal{

  server 192.168.0.153:9091;

  server 192.168.0.154:9091;

  server 192.168.0.155:9091;

}

upstream gitbj{

  server git.itplh.con;

}

server {

    listen       80;

    server_name  gitlocal.com;

    location / {

        proxy_pass http://gitlocal;

        proxy_redirect default;

    }

    location = /50x.html {

        root   html;

    }

}

server {

    listen       80;

    server_name  gitbj.com;

    location / {

        proxy_pass http://gitbj;

        proxy_redirect default;

    }

    location = /50x.html {

        root   html;

    }

}

以上就是nginx的三种反向代理方式你都知道么的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

nginx什么写的

nginx部署~dotnetcore+mvc网站502

nginx用什么语言写的

nginx哪个版本性能好

nginx和apache哪个好

nginx怎么解决跨域问题

正向代理和反向代理

apache和nginx需要一起用吗

nginx的进程名称是什么

教你如何在linux中安装nginx服务器

更多相关阅读请进入《nginx》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...