初识

参考:

知乎-竹汐:nginx有哪些作用?

Nginx官方:nginx documentation

反向代理

以下配置文件中共有三条路由:

  1. /指向/data/www下的静态网页,服务由Nginx执行
  2. /h5/指向frps监听远程frpc客户端的Node.js服务器
  3. /dalai/wx指向frps监听远程frpc客户端的Python运行程序

其中Nginx路由参数比如/h5/,Nginx收到请求会将对应/h5/的请求发给对应的服务,此时对应的服务是Node.js服务,同时将路由也发给Node.js监听的服务,此时Node.js会收到某客户端发来请求/h5/Vue路由的页面数据。

参考:

博客园-郑清:Nginx 配置反向代理

知乎-小知:Nginx配置反向代理,一篇搞定!

配置了反向代理、静态网站,测试后互不干扰

  • /静态网页
  • /h5/内网穿透后反向代理Vue项目
  • /dalai/xw内网穿透后反向代理微信公众号后端项目

/etc/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
server {
listen 80;
# listen [::]:80 default_server;
server_name localhost;
# root /data/www

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

# h5 dev
location /h5/ {
proxy_pass http://127.0.0.1:808;
}

# WX Robot dev
location /dalai/wx {
proxy_pass http://127.0.0.1:88;
}

# H5 build
location / {
root /data/www;
# index index.html index.php index.htm;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}