nginx:限制在一个时间/零大小共享内存区域访问1个请求

时间:2014-07-21 20:28:41

标签: nginx

我想将管理页面限制为一次只有1个请求(如:一次只能有1个人查看该页面)。该页面可以通过端口>到达。 http://admin.url.com:8010。如果我从文档中正确理解,我需要在nginx配置http块中指定limit_conn_zone,在相关服务器块中指定limit_conn

这是我的nginx.conf文件的简化版本:

http {

    limit_conn_zone $server_name zone=server:10m;

    server {
        listen       80;
        server_name  localhost;
        ...
    }


    server {
        listen 8010;
        server_name admin.url.com;
        limit_conn servers 1;
    }
}

此配置文件中还有几个服务器块。

在输入这两行代码并重新启动nginx后,我收到以下错误消息:

$ sudo /etc/init.d/nginx restart
Restarting nginx: nginx: [emerg] zero size shared memory zone "servers"

我在这里做错了什么?我现在必须在每个服务器块中定义limit_conn的问题是什么?

1 个答案:

答案 0 :(得分:0)

如果要限制import asyncio from collections import deque import httpx as httpx from bs4 import BeautifulSoup # Get or build URLs from config def navigate(): urls = deque() for i in range(2, 7): url = f"https://www.example.com/?page={i}" urls.appendleft(url) return urls # Asynchronously fetch and parse data for a single URL async def fetchHTMLandParse(url): client = httpx.AsyncClient() response = await client.get(url) data = BeautifulSoup(response.text, "html.parser") result = data.find_all("div", {"data-component": "search-result"}) for record in result: atag = record.h2.a #Domain URL was defined elsewhere url = f'{domain_url}{atag.get("href")}' products_urls.appendleft(url) loop = asyncio.get_event_loop() products_urls = deque() nav_urls = navigate() fetch_and_parse_workers = [asyncio.ensure_future(fetchHTMLandParse(url)) for url in nav_urls] workers = asyncio.wait([*fetch_and_parse_workers]) loop.run_until_complete(workers) 变量,则必须在服务器部分中设置名称。例如:

$server_name

即使Nginx文档缺少此提示,也请参见https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-http/