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 ...
随机推荐
- net spider(python 网络爬虫)
# -*- coding: utf-8 -*- import urllib2,cookielib from bs4 import BeautifulSoup url="http://www. ...
- redis底层设计(四)——功能的实现
redis中我们会经常用到事务.订阅与发布.Lua脚本以及慢查询日志,接下来我们就一一对他们进行探讨学习. 4.1事务 redis通过MULTI.DISCARD.EXEC和WATCH四个命令来实现事务 ...
- 使用Sharding-Proxy进行分库分表
Sharding-Proxy的使用 1.官网下载 sharding-jdbc的官网http://shardingsphere.io/document/current/cn/manual/shardin ...
- 【LeetCode-数组篇】 1 Two Sum
1 前言 之所以开始刷 LeetCode 上的算法题,一是快面临秋招,第二点是因为提升自己的编程能力,坚持两个月,希望博友们监督. 这个系列打算用 C# 和 Java 编程,为什么用两门语言,因为经历 ...
- SVM(支持向量机)之Hinge Loss解释
Hinge Loss 解释 SVM 求解使通过建立二次规划原始问题,引入拉格朗日乘子法,然后转换成对偶的形式去求解,这是一种理论非常充实的解法.这里换一种角度来思考,在机器学习领域,一般的做法是经验风 ...
- oracle表空间不足,ORA-00604的解决方法
参考文章: http://blog.chinaunix.net/uid-26446098-id-3344813.html 错误信息如下: 从错误的角度可以推出:应该是表空间不足 根据查看表空间的使用情 ...
- H5 36-背景定位属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【学习总结】Git学习-参考廖雪峰老师教程一-Git简介
学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...
- js判断是否是微信浏览器以及重定向
async created () {//这个是判断是否是微信浏览器, let ua = navigator.userAgent.toLowerCase() if (ua.match(/MicroMes ...
- IdentityServer4【QuickStart】之设置和概述
设置和概述 有两个基本的方式来开启一个新的IdentityServer项目: 从头开始 从asp.net Identity模板开始 如果你从头开始,我们提供了一些基于内存中构建的存储,所以你不必一开始 ...