上一篇 <<<Keepalived虚拟vip功能
下一篇 >>>Nginx安全防护汇总(转)
1.业务场景
在前后端分离项目中,需要用到前端页面模拟数据并走流程。当出现异常时,需要根据日志排查,然后接口模拟非常的麻烦。
此时可以通过nginx配置将异常接口信息调用到本地服务联调测试,具体配置如下。
2.nginx配置
server {
listen 80;
server_name api.jarye.com;
charset utf-8;
#正常接口连接到真实服务器
location / {
proxy_pass http://xxx.xxx.xxx.xxx:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Scheme $scheme;
client_max_body_size 10m;
client_body_buffer_size 128k;
#proxy_connect_timeout 90;
#proxy_send_timeout 90;
#proxy_read_timeout 90;
proxy_ignore_client_abort on;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
# 异常接口连接到本地(调试接口)
location /api/ {
proxy_pass http://localhost:8080/webname/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Scheme $scheme;
client_max_body_size 10m;
client_body_buffer_size 128k;
#proxy_connect_timeout 90;
#proxy_send_timeout 90;
#proxy_read_timeout 90;
proxy_ignore_client_abort on;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
3.hosts配置
127.0.0.1 api.jarye.com
推荐阅读:
<<<DNS域名解析过程
<<<初识Nginx与负载均衡
<<<Nginx使用场景之静态服务器
<<<Nginx使用场景之虚拟主机(动静分离)
<<<Nginx使用场景之反向代理
<<<Nginx使用场景之负载均衡和故障转移(主从)
<<<Nginx使用场景之跨域解决
<<<Nginx使用场景之资源压缩
<<<Nginx使用场景之数据缓存
<<<Nginx Location指令详解
<<<Nginx全局变量
<<<Nginx导致图片下载失败的原因分析
<<<Nginx+Consul+upSync实现动态负载均衡
<<<Nginx+Lvs+keepAlived实现高可用
<<<Linux环境安装Nginx
<<<Linux环境安装keepAlived
<<<Keepalived虚拟vip功能
<<<Nginx安全防护汇总(转)