首页 > 系统相关 >nginx反向代理配置介绍

nginx反向代理配置介绍

时间:2024-02-23 15:01:21浏览次数:35  
标签:set header modules 代理 module nginx version 反向

近期搭建portal网站,发现了nginx的强大,跟大家分享一下,背景知识,nginx代理过程

发现:nginx中也可以加入第三方扩展来增强其功能,通常就是下载该模块然后再重新编译nginx加入该模块,比如:https://github.com/openresty/headers-more-nginx-module

此外还有一些打包好的nginx增强包,不用编译,可以直接用apt-get install 来安装

一、nginx 包合集介绍:

nginx 除了我们日常使用的nginx版本之外还有其他包:

nginx-light: "basic version"

The minimal set of modules for basic functionality.

nginx-naxsi: "version with naxsi"

The minimal set, plus the hardened "Nginx Anti Xss & Sql Injection" configuration and its required plugins.

nginx-core: "core version"

The standard nginx deployment, less the third-party modules.

This is the first Canonical-supported nginx package. It's in the Ubuntu "main" repository instead of the community-supported "universe" repository. See the announcement "nginx-core is now in Ubuntu Trusty 14.04 Main!" on an archive of the maintainer's unofficial (older and now defunct) blog or on the copy of the old post on the maintainer's unofficial blog:

none of the already-established flavors of nginx are included in Ubuntu Main (nginx-light, nginx-full, nginx-extras, and nginx-naxsi). The Ubuntu Security Team has said that the third-party modules are wildly different in coding and therefore cannot be supported.

To that end, we created a package called nginx-core which has been included in the Main repository. This package contains only the modules that ship with the stock nginx tarball. We do not include any third-party modules with this package, just the modules that come from NGINX upstream.

nginx-full: "standard version"

The standard nginx deployment, including frequently-used third-party modules.

nginx-extras: "extended version"

The standard nginx deployment plus several infrequently-used and largish modules.

 

功能最全面的就是nginx-extras了,安装方法 apt-get install nginx-extras,更详细的信息可以查看https://askubuntu.com/questions/553937/what-is-the-difference-between-the-core-full-extras-and-light-packages-for-ngi

二、nginx配置使用简介,及其增强功能

比较实用的第三方模块 headers-more-nginx-module,通过引入该模块,然后就可以对服务器的返回值进行个性化修改(去除某些安全性限制)

如下配置文件示例:

load_module modules/ngx_http_headers_more_filter_module.so;  #此句引入了增强模块 headers-more-nginx-module
......
  server {
    listen       8080;
    server_name  localhost;

    location / {
      if ($request_method = 'OPTIONS') {   #可以通过逻辑判断进行配置
          return 204;
      }
      root   /app/frontend/dist;
      try_files $uri $uri/ /app/frontend/dist/index.html /index.html index.html =404;
    }
  }
  # 监听jenkins
  server {
    listen       8081;
    server_name  localhost;

    location / {
      resolver 10.96.0.10 ipv6=off;
      proxy_set_header  X-Real-IP $remote_addr;     #proxy_set_header  对应转发到服务器的request header设置
      add_header X-Forwarded-For $remote_addr;  #add_header 对应从服务器返回给客户端的response header 设置
      proxy_pass https://atp-jenkins.mcd.megvii-inc.com;
      more_set_headers 'X-Frame-Options: ALLOWALL';       #可以重新修改返回值
      proxy_redirect https://atp-jenkins.mcd.megvii-inc.com/ http://10.122.130.254:38081/;
    }
  }
}

 

标签:set,header,modules,代理,module,nginx,version,反向
From: https://www.cnblogs.com/shuchengxiang/p/18029534

相关文章

  • docker启动nginx https自签名证书配置
    启动测试应用时,有时需要自己配置证书签名:1使用系统自带opensslopensslreq\>-x509\>-nodes\>-days365\>-newkeyrsa:2048\>-keyoutexample.key\>-outexample.crt各参数含义:req:处理证书签署请求。-x509:生成自签名证书。-nodes:跳过为证书设置密码......
  • 腾讯云Linux服务器 前端Nginx+后端 项目部署
    一、前端项目部署1.安装nginx服务器:在root目录下创建services文件并下载nginx源文件【nginx-1.21.6.tar.gz】 建议尽量选择稳定版本下载  nginx官网下载地址​​​​cd/rootmkdirservicescdservicescurl-onginx-1.21.6.tar.gzhttp://nginx.org/download/......
  • ubutun部署nginx 静态页面资源
    本教程使用安装包安装安装前你需要安装以下依赖apt-getinstallgccapt-getinstalllibpcre3libpcre3-devapt-getinstallzlib1gzlib1g-devsudoapt-getinstallopensslsudoapt-getinstalllibssl-dev说明:Nginx是高度自由化的Web服务器,它的功能是由许多模块来支持......
  • Docker Swarm部署nginx+api-service实现负载均衡
    背景介绍api服务开发完毕之后如何快速部署实现负载均衡。如果不是重量级的项目,非常建议使用DockerSwarm来实现,非常简单高效且稳定。关于DockerSwarm集群的构建详见我的另一篇博客:DockerSwarm集群搭建相关文件准备(这里以一个ocr服务为例)docker-compose.ymlversion:'......
  • Vue学习笔记10--数据代理
    数据代理:通过一个对象代理对另一个对象属性的操作(读或写) 代码如下所示:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0">......
  • nginx与php pathinfo(TP5框架适用)
    最近在试用fastadmin这一个框架,是由tp5进行二开后的一款框架。fastadmin里面有个代码,要获取pathinfo否则会重定向到登录页,而默认的nginx配置获取的pathinfo一直为空,就导致无法正常进入后台。通过查找资料后,发现pathinfo是php的产物,与nginx无关。如果要让nginx把pathinfo环境变量......
  • nginx日志切割备份
    直接上脚本#!/bin/bash#源日志目录logs_path="/logs/nginx"#备份日志目录back_logs_path="${logs_path}/backup/$(date-d'yesterday'+'%F')"#创建备份目录,以日期命名,注意,每天零点整切割,开始记录新的一天的日志,备份目录应该是昨天mkdir-p${back_logs_path}#重命......
  • Nginx之SSI
    一、简介    SSI【ServerSideInclde】。基于服务端的网页制作技术,即服务端包含。该项目中用到了Nginx中的SSI模块的include命令,这个命令会包含一个页面,然后在nginx服务器中展开。二、使用    2.1、开启SSI        Linux路径地址为:   ......
  • nginx的安装(文心一言)
    在Ubuntu中安装Nginx可以通过APT包管理器进行。以下是在Ubuntu中安装Nginx的步骤:1.更新软件包列表:首先,打开终端并更新您的软件包列表,以确保您安装的是最新的软件包。sudoaptupdate2.安装Nginx:接下来,使用APT包管理器安装Nginx。sudoaptinstallnginx安装过程中,您可能会被提......
  • proxy代理里面的Reflect
    Reflect对象经常和Proxy代理一起使用,原因有三点:Reflect提供的所有静态方法和Proxy第2个handle参数方法是一模一样的。Proxyget/set()方法需要的返回值正是Reflect的get/set方法的返回值,可以天然配合使用,比直接对象赋值/获取值要更方便和准确。receiver参数具有不可替代性。......