搭建Nginx七层反向代理

2019-11-22 09:34:41来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

搭建Nginx七层反向代理

基于https://www.cnblogs.com/Dfengshuo/p/11911406.html这个基础上,在来补充下七层代理的配置方式。简单理解下四层和七层协议负载的区别吧,四层是网络层,负载方式也就是IP+端口的方式负载,七层(应用层)协议的负载方式就是通过URL的方式来进行负载。这就是一个简单通俗的理解吧。

nginx安装方式再讲四层的时候已经说过了,这里就不再继续安装了。就直接上配置文件了

  1 #user  nobody;
  2 worker_processes  1;
  3 
  4 #error_log  logs/error.log;
  5 #error_log  logs/error.log  notice;
  6 #error_log  logs/error.log  info;
  7 #pid        logs/nginx.pid;
  8 events {
  9     worker_connections  1024;
 10 }
 11 
 12 http {
 13     include       mime.types;
 14     default_type  application/octet-stream;
 15     #access_log  logs/access.log  main;
 16     sendfile        on;
 17     #tcp_nopush     on;
 18     #keepalive_timeout  0;
 19     keepalive_timeout  65;
 20     #gzip  on;
 21     server {
 22         listen       80;       #代理端口
 23         server_name  10.156.128.251;    #代理名称
 24         large_client_header_buffers 4 128k;
 25         client_max_body_size 300m;
 26         client_body_buffer_size 128k;
 27         proxy_connect_timeout 600;
 28         proxy_read_timeout 600;
 29         proxy_send_timeout 600;
 30         proxy_buffer_size 64k;
 31         proxy_buffers   4 32k;
 32         proxy_busy_buffers_size 64k;
 33         proxy_temp_file_write_size 64k;
 34         #charset koi8-r;
 35         #access_log  logs/host.access.log  main;
 36         location / {
 37           # root   html;
 38             index  index.html index.htm;
 39             proxy_pass   http://10.156.128.201/;       #要跳转server的IP
 40             proxy_set_header X-Real-IP $remote_addr;
 41             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 42             proxy_set_header Host $host:$server_port;
 43 
 44 
 45         }
 46 
 47         #error_page  404              /404.html;
 48 
 49         # redirect server error pages to the static page /50x.html
 50         #
 51         error_page   500 502 503 504  /50x.html;
 52         location = /50x.html {
 53             root   html;
 54         }
 55 
 56         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 57         #
 58         #location ~ \.php$ {
 59         #    proxy_pass   http://127.0.0.1;
 60         #}
 61 
 62         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 63         #
 64         #location ~ \.php$ {
 65         #    root           html;
 66         #    fastcgi_pass   127.0.0.1:9000;
 67         #    fastcgi_index  index.php;
 68         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 69         #    include        fastcgi_params;
 70         #}
 71 
 72         # deny access to .htaccess files, if Apache's document root
 73         # concurs with nginx's one
 74         #
 75         #location ~ /\.ht {
 76         #    deny  all;
 77         #}
 78     }
 79 
 80 
 81     # another virtual host using mix of IP-, name-, and port-based configuration
 82     #
 83     #server {
 84     #    listen       8000;
 85     #    listen       somename:8080;
 86     #    server_name  somename  alias  another.alias;
 87 
 88     #    location / {
 89     #        root   html;
 90     #        index  index.html index.htm;
 91     #    }
 92     #}
 93 
 94 
 95     # HTTPS server
 96     #
 97     #server {
 98     #    listen       443 ssl;
 99     #    server_name  localhost;
100 
101     #    ssl_certificate      cert.pem;
102     #    ssl_certificate_key  cert.key;
103 
104     #    ssl_session_cache    shared:SSL:1m;
105     #    ssl_session_timeout  5m;
106 
107     #    ssl_ciphers  HIGH:!aNULL:!MD5;
108     #    ssl_prefer_server_ciphers  on;
109 
110     #    location / {
111     #        root   html;
112     #        index  index.html index.htm;
113     #    }
114     #}
115 
116 }
View Code

当然,笔者这份配置文件没有进行优化,只是实现了代理效果,自己也可以根据需求进行优化


原文链接:https://www.cnblogs.com/Dfengshuo/p/11911786.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:搭建Nginx四层反向代理

下一篇:Linux命令(自己工作常用)