关于nginx:Nginx-代理服务器

2次阅读

共计 12988 个字符,预计需要花费 33 分钟才能阅读完成。

Nginx- 代理服务器

作者 | WenasWei

一 Nginx 代理服务器

1.1 Nginx 简介

Nginx 是一款高性能的 HTTP 服务器 / 反向代理服务器及 IMAP/POP3/SMTP 代理服务器。由俄罗斯的程序设计师 Igor Sysoev 所开发,官网测试 Nginx 可能支撑持 5 万并发链接,并且 CPU、内存等资源耗费却非常低,运行十分稳固。

Nginx 代码齐全用 C 语言从头写成,以事件驱动的形式编写,所以有十分好的性能,同时也是一个十分高效的反向代理、负载平衡服务器。在性能上,Nginx 占用很少的系统资源,能反对更多的并发连贯,达到更高的拜访效率;在性能上,Nginx 是优良的代理服务器和负载平衡服务器;在装置配置上,Nginx 安装简单、配置灵便。

截至 2019 年 12 月,差不多世界上每 3 个网站中就有 1 个应用 Nginx。

Nginx 反对热部署,启动速度特地快,还能够在不间断服务的状况下对软件版本或配置进行降级,即便运行数月也无需重新启动。

在微服务的体系之下,Nginx 正在被越来越多的我的项目采纳作为网关来应用,配合 Lua 做限流、熔断等管制。

1.2 Nginx 的利用场景

  • (1)HTTP 服务器:Nginx 是一个 HTTP 服务能够独立提供 HTTP 服务。能够做网页动态服务器。
  • (2)虚拟主机:能够实现在一台服务器虚构出多个网站。例如集体网站应用的虚拟主机。
  • (3)反向代理,负载平衡:当网站的访问量达到肯定水平后,单台服务器不能满足用户的申请时,须要用多台服务器集群能够应用 Nginx 做反向代理。并且多台服务器能够均匀分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的状况。

二 Nginx 常用命令

2.1 Linux 下 Nginx 常用命令

nginx 的应用比较简单,就是几条命令。

nginx -s stop       #疾速敞开 Nginx,可能不保留相干信息,并迅速终止 web 服务。nginx -s quit       #安稳敞开 Nginx,保留相干信息,有安顿的完结 web 服务。nginx -s reload     #因扭转了 Nginx 相干配置,须要从新加载配置而重载。nginx -s reopen     #从新关上日志文件。nginx -c filename   #为 Nginx 指定一个配置文件,来代替缺省的。nginx -t            #不运行,而仅仅测试配置文件。nginx 将查看配置文件的语法的正确性,并尝试关上配置文件中所援用到的文件。nginx -v            #显示 nginx 的版本。nginx -V            #显示 nginx 的版本,编译器版本和配置参数。

在 linux 的 sbin 目录下中输出:./nginx 代替下面的 nginx

如果不想每次都敲命令,能够在 nginx 装置目录下新添一个启动批处理文件 startup.bat,双击即可运行。内容如下:

  • 验证 Nginx 配置文件是否正确

    nginx -t -c /conf/nginx.conf
@echo off
#rem 如果启动前曾经启动 nginx 并记录下 pid 文件,会 kill 指定过程
nginx -s stop

#rem 测试配置文件语法正确性
nginx -t -c nginx.conf

#rem 显示版本信息
nginx -v

#rem 依照指定配置去启动 nginx
nginx -c nginx.conf

2.2 windows 下 Nginx 常用命令

  • windows 下其余常用命令

    nginx.exe -s stop       #疾速敞开 Nginx,可能不保留相干信息,并迅速终止 web 服务。nginx.exe -s quit       #安稳敞开 Nginx,保留相干信息,有安顿的完结 web 服务。nginx.exe -s reload     #因扭转了 Nginx 相干配置,须要从新加载配置而重载。nginx.exe -s reopen     #从新关上日志文件。nginx.exe -c filename   #为 Nginx 指定一个配置文件,来代替缺省的。nginx.exe -t            #不运行,而仅仅测试配置文件。nginx 将查看配置文件的语法的正确性,并尝试关上配置文件中所援用到的文件。nginx.exe -v            #显示 nginx 的版本。nginx.exe -V            #显示 nginx 的版本,编译器版本和配置参数。
  • cmd 命令窗口查看 Nginx 启动命令

    tasklist /fi "imagename eq nginx.exe"

    下图后果为启动胜利

  • 验证 Nginx 配置文件是否正确

    nginx.exe -t -c \conf\nginx.conf

三 Nginx 应用案例

上面将介绍 Nginx 的三种部署应用案例:

  • Windows 部署应用 Nginx
  • Linux(Ubuntu) 部署应用 Nginx
  • 基于 Linux(Ubuntu) 应用 Docker 容器化引擎技术部署应用 Nginx

3.1 Windows 部署应用 Nginx

(1)官网下载 nginx

最新版本 nginx-1.9.9,下载地址:

http://nginx.org/download/nginx-1.9.9.zip

下载后解压,解压后如下

(2)启动 nginx

有很多种办法启动 nginx

  • 间接双击 nginx.exe,双击后一个彩色的弹窗一闪而过
  • 关上 cmd 命令窗口,切换到 nginx 解压目录下,输出命令 nginx.exe 或者 start nginx,回车即可

留神:

启动前能够看到 Nginx 默认应用启动监听端口为 80, 须要查看 80 端口是否被占用,可应用命令:

  • netstat -ano | findstr 0.0.0.0:80
  • netstat -ano | findstr "80"

如若须要自定义其余端口也须要查看端口是否被占用,批改配置文件启动前也能够进行配置文件查看是否配置失常,查看命令:

nginx.exe -t -c \conf\nginx.conf

查看后果如下图所示:

当咱们批改了 nginx 的配置文件 nginx.conf 时,不须要敞开 nginx 后重新启动 nginx,只须要执行命令 nginx -s reload 即可让改变失效

(3)查看 nginx 是否启动胜利

间接在浏览器地址栏输出网址 http://localhost:80,回车,呈现以下页面阐明启动胜利

(4)配置动态页面拜访
  • 在当前目录下创立 404test 测试文件夹,增加测试 index.html,html 内容页面代码地址:

程序猿 404 应用 index.html 页面代码地址

如下两张图所示:

  • 新增批改配置文件: \conf\nginx.conf

      server {
          listen       80;
          server_name  localhost;
          
          location / {
              root   C:/Users/wenas/Downloads/nginx-1.9.9/conf/;
              index  index.html index.htm;
          }
    
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {root   html;}
    
      }
  • 重新启动胜利后,再次拜访页面, 拜访地址: http://localhost:80

拜访后果如图所示:

(5)配置代理地址拜访
  • 增加转发百度页面地址

      server {
          listen       80;
          server_name  localhost;
          # 配置创立的 testindex.html 目录地址
          location / {
              root   C:/Users/wenas/Downloads/nginx-1.9.9/404test/;
              index  index.html index.htm;
          }
    
          location /baidu {
                  proxy_pass http://www.baidu.com/;
                  proxy_connect_timeout 10s;
          }
    
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {root   html;}
      }
  • 重新启动胜利后,再次拜访页面, 拜访地址: http://localhost:80/baidu/

拜访后果如图所示:

能够看到 url 地址为代理的百度地址,内容数据由百度的接口提供。

(6)敞开 nginx

如果应用 cmd 命令窗口启动 nginx,敞开 cmd 窗口是不能完结 nginx 过程的,可应用两种办法敞开 nginx

  • 输出 nginx 命令: nginx -s stop(疾速进行 nginx) 或 nginx -s quit(残缺有序的进行 nginx)
  • 应用 taskkill : taskkill /f /t /im nginx.exe

3.2 Linux 批改数据源与切换 root

1、Linux 零碎版本

应用 lsb_release -a 查看到 Linux 零碎为 Ubuntu 18.04.2 LTS

$ lsb_release -a
LSB Version:    core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
  • 留神:Codename 为 xenial,该名称为咱们 Ubuntu 零碎的名称,批改数据源须要用到该名称
2、编辑数据源
$ vi /etc/apt/sources.list
  • 留神:要先删除原先 sources.list 所有的文件内容,能够应用 echo > sources.lis 一键清空
3、增加阿里云的数据源
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
4、留神肯定要更新数据源能力应用
$ apt-get update
5、上面形式对立应用 root 账户操作, 防止权限问题
# 切换至 root 用户
$ sudo su root

3.3 Linux 部署 Nginx

Linux 部署 Nginx 目前反对两种装置形式, 一种是 apt-get 的形式, 另一种是依据包装置的形式。

3.3.1 apt-get 装置形式

1、apt-get 下载 Nginx
$ apt-get install nginx
2、查看 nginx 是否装置胜利
$ nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
3、Nginx 文件目录与批改配置文件

Nginx 文件装置实现之后的文件地位

  • /usr/sbin/nginx:Nginx 主程序
  • /etc/nginx:寄存配置文件
  • /usr/share/nginx:寄存动态文件
  • /var/log/nginx:寄存日志

进入到配置文件地址批改配置文件 nginx.conf:

$ cd /etc/nginx
$ ll

total 64
drwxr-xr-x  6 root root 4096 Apr 26 23:55 ./
drwxr-xr-x 94 root root 4096 Apr 25 15:40 ../
drwxr-xr-x  2 root root 4096 Jan 11  2020 conf.d/
-rw-r--r--  1 root root 1077 Feb 12  2017 fastcgi.conf
-rw-r--r--  1 root root 1007 Feb 12  2017 fastcgi_params
-rw-r--r--  1 root root 2837 Feb 12  2017 koi-utf
-rw-r--r--  1 root root 2223 Feb 12  2017 koi-win
-rw-r--r--  1 root root 3957 Feb 12  2017 mime.types
-rw-r--r--  1 root root 2959 Apr 26 23:55 nginx.conf
-rw-r--r--  1 root root  180 Feb 12  2017 proxy_params
-rw-r--r--  1 root root  636 Feb 12  2017 scgi_params
drwxr-xr-x  2 root root 4096 Apr 25 15:40 sites-available/
drwxr-xr-x  2 root root 4096 Apr 25 15:40 sites-enabled/
drwxr-xr-x  2 root root 4096 Apr 25 15:40 snippets/
-rw-r--r--  1 root root  664 Feb 12  2017 uwsgi_params
-rw-r--r--  1 root root 3071 Feb 12  2017 win-utf

批改配置文件如下:

#user  nobody;
worker_processes  1;

events {worker_connections  1024;}


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

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       7070;
        server_name  localhost;

        location / {
            # 上传程序员 404-index.html 到该指定目录下
            root   /usr/share/nginx/html/;
            index  index.html index.htm;
        }

    }
}
4、验证 Nginx 配置文件

验证配置文件是否配置正确

$ nginx -t -c /etc/nginx/nginx.conf 

验证后果如下:

$ nginx -t -c /etc/nginx/nginx.conf 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
5、启动 Nginx

启动 Nginx 指令:

service nginx start

查看 Nginx 启动过程:

$ ps -ef|grep nginx
root      1980     1  0 20:14 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
nobody    1983  1980  0 20:14 ?        00:00:00 nginx: worker process
root      2051 11018  0 20:14 pts/0    00:00:00 grep --color=auto nginx
root     25087 25065  0 Apr25 ?        00:00:00 nginx: master process nginx -g daemon off;
systemd+ 25160 25087  0 Apr25 ?        00:00:00 nginx: worker process
6、查看 Nginx 配置拜访界面

在浏览器面上关上 URL: ip:7070

就能看到咱们可恶的程序猿 404 了

  • 留神: 云服务器须要凋谢拜访端口 7070
7、卸载 apt-get 装置的 nginx
# 彻底卸载 nginx
$ apt-get --purge autoremove nginx

#查看 nginx 的版本号
$ nginx -v

3.3.2 包装置形式

1、装置依赖包
apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev

# Ubuntu14.04 的仓库中没有发现 openssl-dev,由上面 openssl 和 libssl-dev 代替
#apt-get install openssl openssl-dev
sudo apt-get install openssl 
sudo apt-get install libssl-dev
2、装置 nginx
cd /usr/local
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz 

3、编译 nginx
# 进入 nginx 目录
/usr/local/nginx/nginx-1.13.7
# 执行命令
./configure
# 执行 make 命令
make
# 执行 make install 命令
make install
4、启动 nginx
# 进入 nginx 启动目录
cd /usr/local/nginx/sbin
# 启动 nginx
./nginx

拜访 nginx

网页输出 ip 地址: 凋谢端口,拜访胜利,到此,nginx 装置结束

3.3 基于 Docker 部署应用 Nginx

本篇部署须要应用到 Docker 容器化引擎技术部署,须要在 Linux 上装置 Docker 环境与 Docker-compose 环境

1、查看 Docker 环境
$ docker -v
Docker version 18.09.7, build 2d0083d

$ docker-compose -v
docker-compose version 1.25.0-rc4, build 8f3c9c58
扩大常识:
  • 装置 Docker 环境
  • 装置 Docker-Compose 环境
  • Docker 常用命令
  • Docker-Compose 常用命令
2、拉取 Nginx 镜像
docker pull nginx
3、Docker-compose 配置文件与 Nginx 配置文件
  • (1)操作文件目录构造

操作文件目录为: /usr/local/docker/nginx

文件目录为:

- conf/
    - nginx.conf
- docker-compose.yml
  • (1)docker-compose.yml 配置文件

    version: '3.1'
    services:
    nginx:
      restart: always
      image: nginx
      container_name: nginx
      ports:
        - 8081:80
      volumes:
        - ./conf/nginx.conf:/etc/nginx/nginx.conf
        - /home/wenas/html/:/home/wenas/html/
  • (2)nginx.conf 配置文件

    user  nginx;
    worker_processes  1;
    
    events {worker_connections  1024;}
    
    http {
      include       mime.types;
      default_type  application/octet-stream;
    
      sendfile        on;
    
      keepalive_timeout  65;
    
      # 配置一个虚拟主机
      server {
          listen 80;
    
          location /testhtml/ {
             alias  /home/wenas/html/;
             autoindex on;
          }
      }
          
    }
    
4、启动 Nginx-Docker 容器
  • 启动命令

    $ docker-compose up -d
    Starting nginx ... done
  • 查看启动的 Nginx 容器

    $ docker ps
    CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                            NAMES
    8141bae75054        nginx                    "nginx -g'daemon of…"   12 days ago         Up 26 seconds       0.0.0.0:8081->80/tcp                             nginx
5、拜访界面

拜访 URL : IP:8081/testhtml/

四 Nginx 应用案例

4.1 负载平衡配置

网站在理论经营过程中,多半都是有多台服务器运行着同样的 app,这时须要应用负载平衡来分流。

nginx 也能够实现简略的负载平衡性能。

假如这样一个利用场景:将利用部署在 192.168.1.11:80、192.168.1.12:80、192.168.1.13:80 三台 linux 环境的服务器上。网站域名叫 www.helloworld.com,公网 IP 为 192.168.1.11。在公网 IP 所在的服务器上部署 nginx,对所有申请做负载平衡解决。

nginx.conf 配置如下:

http {
     #设定 mime 类型, 类型由 mime.type 文件定义
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    #设定日志格局
    access_log    /var/log/nginx/access.log;

    #设定负载平衡的服务器列表
    upstream load_balance_server {
        #weigth 参数示意权值,权值越高被调配到的几率越大
        server 192.168.1.11:80   weight=5;
        server 192.168.1.12:80   weight=1;
        server 192.168.1.13:80   weight=6;
    }

   #HTTP 服务器
   server {
        #侦听 80 端口
        listen       80;
        
        #定义应用 www.xx.com 拜访
        server_name  www.helloworld.com;

        #对所有申请进行负载平衡申请
        location / {
            root        /root;                 #定义服务器的默认网站根目录地位
            index       index.html index.htm;  #定义首页索引文件的名称
            proxy_pass  http://load_balance_server ;# 申请转向 load_balance_server 定义的服务器列表

            #以下是一些反向代理的配置(可选择性配置)
            #proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            #后端的 Web 服务器能够通过 X -Forwarded-For 获取用户实在 IP
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_connect_timeout 90;          #nginx 跟后端服务器连贯超时工夫(代理连贯超时)
            proxy_send_timeout 90;             #后端服务器数据回传工夫(代理发送超时)
            proxy_read_timeout 90;             #连贯胜利后,后端服务器响应工夫(代理接管超时)
            proxy_buffer_size 4k;              #设置代理服务器(nginx)保留用户头信息的缓冲区大小
            proxy_buffers 4 32k;               #proxy_buffers 缓冲区,网页均匀在 32k 以下的话,这样设置
            proxy_busy_buffers_size 64k;       #高负荷下缓冲大小(proxy_buffers*2)proxy_temp_file_write_size 64k;    #设定缓存文件夹大小,大于这个值,将从 upstream 服务器传
            
            client_max_body_size 10m;          #容许客户端申请的最大单文件字节数
            client_body_buffer_size 128k;      #缓冲区代理缓冲用户端申请的最大字节数
        }
    }
}

4.2 网站有多个 webapp 的配置

当一个网站性能越来越丰盛时,往往须要将一些性能绝对独立的模块剥离进去,独立保护。这样的话,通常,会有多个 webapp。

举个例子:如果 www.helloworld.com 站点有好几个 webapp,finance(金融)、product(产品)、admin(用户核心)。拜访这些利用的形式通过上下文 (context) 来进行辨别:

www.helloworld.com/finance/

www.helloworld.com/product/

www.helloworld.com/admin/

咱们晓得,http 的默认端口号是 80,如果在一台服务器上同时启动这 3 个 webapp 利用,都用 80 端口,必定是不成的。所以,这三个利用须要别离绑定不同的端口号。

那么,问题来了,用户在理论拜访 www.helloworld.com 站点时,拜访不同 webapp,总不会还带着对应的端口号去拜访吧。所以,你再次须要用到反向代理来做解决。

配置也不难,来看看怎么做吧:

http {
    #此处省略一些根本配置    
    upstream product_server{server www.helloworld.com:8081;}    
    upstream admin_server{server www.helloworld.com:8082;}    
    upstream finance_server{server www.helloworld.com:8083;}

    server {
        #此处省略一些根本配置
        #默认指向 product 的 server
        location / {proxy_pass http://product_server;}
        location /product/{proxy_pass http://product_server;}
        location /admin/ {proxy_pass http://admin_server;}        
        location /finance/ {proxy_pass http://finance_server;}
    }
}

4.3 https 反向代理配置

一些对安全性要求比拟高的站点,可能会应用 HTTPS(一种应用 ssl 通信规范的平安 HTTP 协定)。

这里不科普 HTTP 协定和 SSL 规范。然而,应用 nginx 配置 https 须要晓得几点:

  • HTTPS 的固定端口号是 443,不同于 HTTP 的 80 端口
  • SSL 规范须要引入平安证书,所以在 nginx.conf 中你须要指定证书和它对应的 key
    其余和 http 反向代理根本一样,只是在 Server 局部配置有些不同。
  #HTTP 服务器
  server {
      #监听 443 端口。443 为出名端口号,次要用于 HTTPS 协定
      listen       443 ssl;

      #定义应用 www.xx.com 拜访
      server_name  www.helloworld.com;

      #ssl 证书文件地位(常见证书文件格式为:crt/pem)
      ssl_certificate      cert.pem;
      #ssl 证书 key 地位
      ssl_certificate_key  cert.key;

      #ssl 配置参数(选择性配置)ssl_session_cache    shared:SSL:1m;
      ssl_session_timeout  5m;
      #数字签名,此处应用 MD5
      ssl_ciphers  HIGH:!aNULL:!MD5;
      ssl_prefer_server_ciphers  on;

      location / {
          root   /root;
          index  index.html index.htm;
      }
  }

4.4 动态站点配置

有时候,咱们须要配置动态站点(即 html 文件和一堆动态资源)。

举例来说:如果所有的动态资源都放在了 /app/dist 目录下,咱们只须要在 nginx.conf 中指定首页以及这个站点的 host 即可。

配置如下:

worker_processes  1;

events {worker_connections  1024;}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    gzip on;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript image/jpeg image/gif image/png;
    gzip_vary on;

    server {
        listen       80;
        server_name  static.zp.cn;

        location / {
            root /app/dist;
            index index.html;
            #转发任何申请到 index.html
        }
    }
}

而后,增加 HOST:

127.0.0.1 static.zp.cn

此时,在本地浏览器拜访 static.zp.cn,就能够拜访动态站点了。

4.5 跨域解决方案

web 畛域开发中,常常采纳前后端拆散模式。这种模式下,前端和后端别离是独立的 web 应用程序,例如:后端是 Java 程序,前端是 React 或 Vue 利用。

各自独立的 web app 在相互拜访时,势必存在跨域问题。解决跨域问题个别有两种思路:

  • COR

在后端服务器设置 HTTP 响应头,把你须要运行拜访的域名退出退出 Access-Control-Allow-Origin 中。

  • jsonp

把后端依据申请,结构 json 数据,并返回,前端用 jsonp 跨域。

这两种思路,本文不展开讨论。

须要阐明的是,nginx 依据第一种思路,也提供了一种解决跨域的解决方案。

举例:www.helloworld.com 网站是由一个前端 app,一个后端 app 组成的。前端端口号为 9000,后端端口号为 8080。

前端和后端如果应用 http 进行交互时,申请会被回绝,因为存在跨域问题。来看看,nginx 是怎么解决的吧:

首先,在 enable-cors.conf 文件中设置 cors:

# allow origin list
set $ACAO '*';

# set single origin
if ($http_origin ~* (www.helloworld.com)$) {set $ACAO $http_origin;}

if ($cors = "trueget") {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}

if ($request_method = 'OPTIONS') {set $cors "${cors}options";
}

if ($request_method = 'GET') {set $cors "${cors}get";
}

if ($request_method = 'POST') {set $cors "${cors}post";
}

接下来,在你的服务器中 include enable-cors.conf 来引入跨域配置:

# ----------------------------------------------------
# 此文件为我的项目 nginx 配置片段
# 能够间接在 nginx config 中 include(举荐)# 或者 copy 到现有 nginx 中,自行配置
# www.helloworld.com 域名需配合 dns hosts 进行配置
# 其中,api 开启了 cors,需配合本目录下另一份配置文件
# ----------------------------------------------------
upstream front_server{server www.helloworld.com:9000;}
upstream api_server{server www.helloworld.com:8080;}

server {
  listen       80;
  server_name  www.helloworld.com;

  location ~ ^/api/ {
    include enable-cors.conf;
    proxy_pass http://api_server;
    rewrite "^/api/(.*)$" /$1 break;
  }

  location ~ ^/ {proxy_pass http://front_server;}
}

参考文档:

  • [1] Nginx 官网: https://www.nginx.cn/
  • [2] 百度百科: https://baike.baidu.com/item/…
  • [3] 将王相. 博客园: https://www.cnblogs.com/jiang…,2018-02-28 .
  • [4] 雨点的名字. 博客园: https://www.cnblogs.com/qdhxh… , 2018-04-22 .
  • [5] 程序媛小雪.CSDN: https://blog.csdn.net/qq_2383… , 2018-10-31 .
正文完
 0