下载前端项目

项目下载地址:

解压后放到nginx目录下的html文件

nginx
├── html
│ ├── app-web
│ ├── 50x.html
│ └── index.html

使用Nginx

配置Nginx文件

在nginx安装的conf目录下心间文件夹leadnews.conf,并创建headnews-app.conf文件,内容如下:

Mac的Nginx配置文件路径:/usr/local/etc/nginx/nginx.conf

upstream leadnews-app-gateway {
server localhost:51601;
}

server {
listen 8801;
location / {
root html/app-web/;
index index.html;
}

location ~/app/(.*) {
proxy_pass http://leadnews-app-gateway/$1;
proxy_set_header HOST $host; # 不改变源请求头的值
proxy_pass_request_body on; # 开启获取请求体
proxy_pass_request_headers on; # 开启获取请求头
proxy_set_header X-Real-IP $remote_addr; # 记录真实发出请求的客户端IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 记录代理信息
}
}

在nginx.conf中引入leadnews-app.conf

worker_processes 1;     

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 引入自定义配置文件
include leadnews.conf/*.conf;
}

启动项目

进入bin目录,使用下面命令启动

./nginx

重启命令

./nginx -s reload

Mac命令:brew services stop nginx

访问项目

访问链接:http://localhost:8801/

可以测试登陆网关和服务是否正常。