背景:生产环境部署后端服务,没有负载均导致服务压力过大,可以启用nginx进行反向代理。
准备:1)后端服务启动在8081(可以修改)
2)nginx监听8080(可以修改),转发请求到8081(和后端服务端口一致)
nginx配置
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
# server
server {
listen 8080;
server_name gateway;
charset utf-8;
location / {
root html/www;
index index.html index.htm;
# include /etc/nginx/uwsgi_params;
proxy_pass http://xx.xx.xx.xx:8081; # 填写真实地址
}
error_page 500 502 503 504 /50x.html;
# 日志,需要创建好目录
#access_log /code/datafabric/apigateway/log/gateway.access.log;
#error_log /code/datafabric/apigateway/log/gateway.error.log;
}
}