Nginx tcp限制并发、IP、记日志
L:114


| Syntax: | limit_conn_zone |
|---|---|
| Default: | — |
| Context: | stream |
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
...
limit_conn addr ;
}
| Syntax: | limit_conn_log_level |
|---|---|
| Default: |
limit_conn_log_level error; |
| Context: | stream, server |
Syntax:limit_conn zone number; //上面配置的zone名称 限制并发连接数量
Default:—
Context:stream, server



类似http access访问阶段
| Syntax: | allow |
|---|---|
| Default: | — |
| Context: | stream, server |
| Syntax: | deny |
|---|---|
| Default: | — |
| Context: | stream, server |
server {
...
deny 192.168.1.1;
allow 192.168.1.0/;
allow 10.1.1.0/;
allow :0db8::/;
deny all;
}
log阶段:stream_log模块
| Syntax: | access_log access_log |
|---|---|
| Default: |
access_log off; |
| Context: | stream, server |
| Syntax: | log_format |
|---|---|
| Default: | — |
| Context: | stream |
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
| Syntax: | open_log_file_cache open_log_file_cache |
|---|---|
| Default: |
open_log_file_cache off; |
| Context: | stream, server |
nginx.conf指令演示
server {
listen proxy_protocol; #这里开启了协议
set_real_ip_from 192.168.0.51;
allow 202.112.144.236; #通过protocol协议 允许该ip访问
deny all; #禁用所有IP
return '10004 vars:
bytes_received: $bytes_received
bytes_sent: $bytes_sent
proxy_protocol_addr: $proxy_protocol_addr
proxy_protocol_port: $proxy_protocol_port
remote_addr: $remote_addr
remote_port: $remote_port
realip_remote_addr: $realip_remote_addr
realip_remote_port: $realip_remote_port
server_addr: $server_addr
server_port: $server_port
session_time: $session_time
status: $status
protocol: $protocol
';
}
[root@ conf]# telnet 192.168.0.51
Trying 192.168.0.51...
Connected to 192.168.0.51.
Escape character is '^]'.
PROXY TCP4 202.112.144.236 10.210.12.10 \r\n //这里输入了202.112.144.236地址表示 这样就允许访问了
vars:
bytes_received:
bytes_sent:
proxy_protocol_addr: 202.112.144.236 //查看返回结果
proxy_protocol_port:
remote_addr: 202.112.144.236
remote_port:
realip_remote_addr: 192.168.0.51
realip_remote_port:
server_addr: 192.168.0.51
server_port:
session_time: 2.452
status:
protocol: TCP
Connection closed by foreign host.
Nginx tcp限制并发、IP、记日志的更多相关文章
- Nginx突破高并发的性能优化 - 运维笔记
在日常的运维工作中,经常会用到nginx服务,也时常会碰到nginx因高并发导致的性能瓶颈问题.今天这里简单梳理下nginx性能优化的配置(仅仅依据本人的实战经验而述,如有不妥,敬请指出~) 一.这里 ...
- Nginx网络架构实战学习笔记(五):大访问量优化整体思路、ab压力测试及nginx性能统计模块、nginx单机1w并发优化
文章目录 大访问量优化整体思路 ab压力测试及nginx性能统计模块 ab压力测试及nginx性能统计模块 ab压力测试 nginx性能统计模块 nginx单机1w并发优化 整装待发: socket ...
- Nginx负载均衡反向代理 后端Nginx获取客户端真实IP
Nginx 反向代理后,后端Nginx服务器无法正常获取客户端的真实IP nginx通过http_realip_module模块来实现的这需要重新编译,如果提前编译好了就无需重新编译了1,重新编译ng ...
- nginx获取上游真实IP(ngx_http_realip_module)
realip模块的作用是:当本机的nginx处于一个反向代理的后端时获取到真实的用户IP,如果没有realip模块,nginx的access_log里记录的IP会是反向代理服务器的IP,PHP中$_S ...
- Nginx(三)-- 配置文件之日志管理
1.日志文件的默认存放位置 默认的日志文件存放位置在:nginx/logs/ 文件夹下,logs文件夹下有:access.log error.log nginx.pid 文件 2.nginx. ...
- 在Nginx服务器上屏蔽IP
采集和防止采集是一个经久不息的话题,一方面都想搞别人的东西,另一方面不想自己的东西被别人搞走. 本文介绍如何利用nginx屏蔽ip来实现防止采集,当然也可以通过iptable来实现. 1.查找要屏蔽的 ...
- 13.多级代理下Nginx透传真实IP
1.基于代理(七层负载均衡)情况下 透传客户端的真实IP 环境: 10.0.0.5 proxy_node1 一级代理 10.0.0.6 proxy_node2 二级代理 10.0.0.7 proxy_ ...
- 阿里云Linux CentOS8.1 64位服务器安装LNMP(Linux+Nginx+MySQL+PHP) 并发调试之php-fpm配置及其与Nginx的通信
一.php-fpm的配置 1. php-fpm的配置,首先要关注进程数量. php-fpm的进程管理方式有三种:static.dynamic.ondemand. static方式,开启固定数量(pm. ...
- NGINX杂谈——flask_limiter的IP获取(怎么拿到真实的客户端IP)
本篇博客将 flask_limiter 作为切入点,来记录一下自己对 remote_addr 和 proxy_add_x_forwarded_for 两个变量.X-Real-IP 和 X-Forwar ...
随机推荐
- 【强化学习】用pandas 与 numpy 分别实现 q-learning, saras, saras(lambda)算法
本文作者:hhh5460 本文地址:https://www.cnblogs.com/hhh5460/p/10159331.html 特别感谢:本文的三幅图皆来自莫凡的教程 https://morvan ...
- [CF1137E]Train Car Selection[维护凸壳]
题意 题目链接 分析 首先,如果加到了车头所有之前的车厢都不可能成为答案. 如果加到了车尾,容易发现对于 \(x_2<x_3\) 而言在某个时刻会出现 2 又比 3 优的情况. 具体来讲,如果存 ...
- Android开发常用权限设置
加在AndroidManifest.xml 文件中manifest标签以内,application以外 例如:<!--网络权限 --> <uses-permission androi ...
- MySQL 5.6中如何定位DDL被阻塞的问题
在上一篇文章<MySQL 5.7中如何定位DDL被阻塞的问题>中,对于DDL被阻塞问题的定位,我们主要是基于MySQL 5.7新引入的performance_schema.metadata ...
- LeetCode 905. Sort Array By Parity
905. Sort Array By Parity Given an array A of non-negative integers, return an array consisting of a ...
- python学习第十篇——while 的灵活运用
sandwiches_orders = ['apple','banana','mango',"apple","watermelon"] finished_san ...
- iOS悬浮窗口(无论界面跳转、View始终在视图上显示,可移动)
2016.09.24 23:52* 字数 71 阅读 5925评论 9喜欢 11 让所有界面都显示,最好还是封装一个继承Window的类:JYCWindow. 先看看效果: mygif.gif 关 ...
- 项目集成自动分词系统ansj,实现自定义词库
一,分词系统地址:https://github.com/NLPchina/ansj_seg 二,为什么选择ansj? 1.项目需求: 我们平台要做手机售后的舆情分析,即对购买手机的用户的评论进行分析. ...
- Linux 典型应用之WebServer 安装和配置
Apache的基本操作 安装 yum install httpd 启动 service httpd start 在浏览器中输入以下Ip 发现无法访问 http://192.168.1.109/ 输入 ...
- 通过爬虫程序深入浅出java 主从工作模型
随手做的爬虫程序在 https://github.com/rli07/master_java/blob/master/spider.zip 可下载. 这是我做的系统学习图, 可以参考一下 系统架 ...