搭建Nginx七层反向代理

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

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

搭建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

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

  • 但行好事, 莫问前程 –

Original: https://www.cnblogs.com/Dfengshuo/p/11911786.html
Author: fs_Dong
Title: 搭建Nginx七层反向代理

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585725/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Docker如何镜像加速

    原文链接:https://www.zhoubotong.site/post/69.html在使用Docker 下载镜像时,如果不配置镜像加速,下载镜像会比较慢,因为国内从 Dock…

    Linux 2023年6月6日
    0129
  • 【微服务】Nacos初体验

    SpringCloud – Nacos初体验 😄生命不息,写作不止🔥 继续踏上学习之路,学之分享笔记👊 总有一天我也能像各位大佬一样🏆 一个有梦有戏的人 @怒放吧德德🌝…

    Linux 2023年6月6日
    0102
  • Java并发-建立线程

    一、建立新的线程 方法介绍 1、java.lang.Thread 1.0 Thread(Runnable target) 构造一个新线程,用于调用给定目标的run()方法。 voi…

    Linux 2023年6月7日
    081
  • 第2次作业:支付宝案例分析

    1.介绍产品相关信息 *你选择的产品是? 支付宝 *为什么选择该产品作为分析? 在使用支付宝前,像交学费这种金额比较大的金钱来往都得去银行处理,在银行排队通常需要很多时间,尤其是办…

    Linux 2023年6月8日
    070
  • Android recovery支持adb shell

    Android recovery支持adb shell 近期开发过程注意到recovery不支持adb shell。为了便于调试方便,决定添加此功能。 刚開始我们採用的是user版…

    Linux 2023年5月28日
    092
  • redis限流的3种实现方式

    Redis限流的实现方式有3种,分别是:1、基于Redis的setnx的操作,给指定的key设置了过期实践;2、基于Redis的数据结构zset,将请求打造成一个zset数组;3、…

    Linux 2023年5月28日
    082
  • Centos 7 升级内核

    【背景说明】 在公司进行部署产品时,发公司内部的服务内核资源并不能满足于产品部署条件,于是我和内核就进行了一场风花雪月般的交互,在操作前,本人小白一枚,就在浩瀚的互联网海洋中搜索升…

    Linux 2023年5月27日
    093
  • 表单校验

    HTML <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Typ…

    Linux 2023年6月13日
    087
  • Redis的穿透、击穿、雪崩之间的区别与联系

    [本文出自天外归云的博客园] 缓存穿透 redis查询后有数据库查询的情况,查的数据在数据库里本来就没有,所以缓存里也没有,所以查询穿透了缓存,直接落到了数据库上,这就是缓存穿透 …

    Linux 2023年5月28日
    077
  • NTP服务器实现

    时间服务器是一种计算机网络仪器,它从参考时钟获取实际时间,再利用计算机网络把时间信息传递给用户。虽然还有一些比较少用或过时的协议仍然在使用,但现时最重要及广泛使用,作为时间信息发送…

    Linux 2023年6月7日
    080
  • 解决关闭shell会话窗口则会发现ASP.NET Core应用也会被关闭问题

    统计了三种方法: 一、使用nohup命令即可 【最简单】 nohup dotnet xxxx.dll 【xxxx为应用名称】 一般会报:nohup: ignoring input …

    Linux 2023年6月8日
    0112
  • redis八种基本数据类型及其应用

    NoSQL 开发中或多或少都会用到,也是面试必问知识点。最近这几天的面试每一场都问到了。但是感觉回答的并不好,还有很多需要梳理的知识点。这里通过几篇 Redis 笔记整个梳理一遍,…

    Linux 2023年5月28日
    074
  • Redis缓存查询时报字段无法识别问题-SerializationException: Could not read JSON: Unrecognized xxx

    报错信息: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exce…

    Linux 2023年6月14日
    087
  • windows下安装virtualenv并且配置指定环境

    下面是在windows下通过virtualenv创建虚拟环境, 包括 : 安装virtualenv(使用pip可直接安装) 使用virtualenv创建指定版本的虚拟环境 进入虚拟…

    Linux 2023年6月6日
    093
  • JVM的监控

    JVM的监控 Table of Contents *一、jvm常见监控工具&指令 * 1、 jps:jvm进程状况工具 * 2、jstat: jvm统计信息监控工具 * 3…

    Linux 2023年6月13日
    0121
  • Linux ARMv7中断向量表搬移(2)【转】

    经历过kernel的汇编阶段,进入C语言start_kernel后对中断向量表的位置进行搬移,搬移函数是early_trap_init。 early_trap_init函数的调用流…

    Linux 2023年6月8日
    098
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球