AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[http](server)

Martin Hope
Xowap
Asked: 2024-02-07 19:14:06 +0800 CST

基于 ETag 的内容重新验证

  • 5

我的 CMS 生成相当复杂的页面,因此需要一些时间(大约 2 秒),这远远超出了我向客户端提供页面的时间预算。

然而,对我来说,了解给定页面的当前版本非常便宜,因此我很容易判断给定版本是否仍然是最新的。因此,我希望能够采用基于 ETag 的策略,其中对页面的每个请求都需要重新验证,但如果内容没有更改,服务器将在 10 毫秒内回复。

为了使其有效,我需要在所有客户端之间共享此缓存。只要 ETag 重新验证,我的所有页面对于所有用户都将保持相同,因此我可以安全地共享他们的内容。

为此,我的页面会发出:

Cache-Control: public, no-cache, must-revalidate
ETag: W/"xxx"

当从浏览器进行测试时,效果很好:页面保留在缓存中,每次刷新页面时都会根据服务器重新验证,大多数情况下会得到 304,或者当我更改内容版本时得到 200。

我现在需要的就是在客户端之间共享此缓存。本质上:

  1. A相
    1. 客户端A向代理发送请求
    2. 代理没有缓存,因此询问后端
    3. 后端使用 ETag 回复 200
    4. 代理使用 ETag 回复 200
  2. B期
    1. 客户端B向代理发送相同的请求
    2. 代理已在缓存中,但必须重新验证(因为无缓存且必须重新验证和 ETag)
    3. 后端回复 304(因为重新验证请求包含带有缓存的 ETag 的 If-None-Match 标头)
    4. 代理使用 Etag 回复 200
  3. C期
    1. 客户端 A 再次发送相同的请求,这次使用 If-None-Match
    2. 代理使用提供的 If-None-Match 标头(不是缓存的标头)询问后端
    3. 后端服务器回复304
    4. 代理回复304

我尝试过 nginx,但它需要大量调整才能使其远程工作。然后我尝试了Traefik,才意识到缓存中间件是企业版的一部分。然后我发现 Varnish似乎实现了我想要的。

所以这里我使用我的 Varnish 配置:

vcl 4.0;

backend default {
    .host = "localhost";
    .port = "3000";
}

backend api {
    .host = "localhost";
    .port = "8000";
}

sub vcl_recv {
    if (req.url ~ "^/back/" || req.url ~ "^/_/") {
        set req.backend_hint = api;
    } else {
        set req.backend_hint = default;
    }
}

当然……这没有用。

当改变Cache-Control标头时,我要么从共享缓存中获取结果,但该结果没有重新验证,要么只是传递给客户端,但它似乎从未像我希望的那样将内容保留在缓存中。

为了让这个共享缓存/ETag 重新验证逻辑到位,我缺少什么?我想我错过了一些明显的东西,但无法弄清楚是什么。

http
  • 1 个回答
  • 69 Views
Martin Hope
Richard
Asked: 2023-05-10 02:02:58 +0800 CST

“GET /”是有效的 HTTP 请求吗?

  • 6

我注意到将GET /(+CRLF) 发送到某些网络服务器(例如来自知名搜索提供商)会产生一条HTTP/1.0 200 OK消息。其他网络服务器响应错误HTTP/1.0 400。

据我所知,甚至 HTTP/1.0 也需要版本字段。是GET /(没有协议和主机)标准化、有效的缩短 GET 请求吗?

经过一番挖掘,我发现 1991 年的 HTTP/0.9 定义了以下内容:

  • 该请求由单词“GET”、一个空格、文档地址、[...] 组成。
  • 文档地址将由一个单词组成(即没有空格)。如果在请求行中发现任何其他单词,则必须忽略它们,或者根据完整的 HTTP 规范进行处理

使用 HTTP/0.9,请求似乎是可能的。一些消息来源称其为单线协议。不确定这是否是常识。我不知道也没有见过这个。网络服务器是否打算接受此 HTTP/0.9 请求?

http
  • 1 个回答
  • 70 Views
Martin Hope
Sam Sirry
Asked: 2022-08-23 06:38:25 +0800 CST

HTTP POST 到 CSS 资源如何对 http 攻击者有用?

  • 2

在网络活动激增之后,通过 Cloudflare 代理检查为临时最小 WordPress 站点提供服务的 Apache 的日志,我看到以下条目重复了数百次:

172.71.98.180 - - [22/Aug/2022:01:59:06 +0000] "POST /wp-content/plugins/the-social-links/assets/css/font-awesome.min.css HTTP/1.1" 302 565 "-" "Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2"

现在,HTTP 攻击对我来说不是新闻,但奇怪的是,这种攻击是针对带有 POST 请求的 CSS 资源。

这如何以任何可能的方式对攻击者有用?

http
  • 0 个回答
  • 39 Views
Martin Hope
Mike Cole
Asked: 2022-04-16 09:43:51 +0800 CST

网站上的图像不一致的 403 禁止问题

  • 0

请求嵌入在网页上的图像时,我得到不一致的 HTTP 403 禁止结果。这在 FireFox 中发生得更频繁,但在 Chrome 中也偶尔发生。这个网站已经使用了很多年,几周前才出现。我同时控制网站和服务器,但不确定如何解决此问题。当我刷新页面时,它似乎是导致问题的不同资源组合。

回复:

HTTP/1.1 403 Forbidden
Server: Microsoft-IIS/8.5
X-UA-Compatible: IE=Edge
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=63072000; includeSubDomains;
P3P: Our site does not have a P3P Policy, please see our privacy policy for more information.
Date: Fri, 15 Apr 2022 17:34:15 GMT
Content-Length: 0

要求:

GET /bonds/images/exclamation.png HTTP/1.1
Host: <Redacted>
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0
Accept: image/avif,image/webp,*/*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Referer: <Redacted>
Cookie: <Redacted>
Sec-Fetch-Dest: image
Sec-Fetch-Mode: no-cors
Sec-Fetch-Site: same-origin
If-Modified-Since: Mon, 04 Apr 2022 20:03:08 GMT
Cache-Control: max-age=0
http iis-8.5
  • 1 个回答
  • 89 Views
Martin Hope
Bazim
Asked: 2022-04-03 21:20:27 +0800 CST

Nginx www 不工作

  • 0

我真的不知道为什么我的 nginx 配置不适用于 www。

我的配置是:

server {
    listen 80;
    server_name postimg.cz www.postimg.cz;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443;

    server_name postimg.cz;

    # SSL Configuration
    ssl_certificate /etc/letsencrypt/live/postimg.cz/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/postimg.cz/privkey.pem;
    ssl_session_cache shared:SSL:10m;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GC>
    ssl_prefer_server_ciphers on;

    # See https://hstspreload.org/ before uncommenting the line below.
    # add_header Strict-Transport-Security "max-age=15768000; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header Content-Security-Policy "frame-ancestors 'self'";
    add_header X-Frame-Options DENY;
    add_header Referrer-Policy same-origin;

    root /var/www/postimg.cz;

    # Disable access to sensitive application files
    location ~* (app|content|lib)/.*\.(po|php|lock|sql)$ {
        return 404;
    }
    location ~* composer\.json|composer\.lock|.gitignore$ {
        return 404;
    }
    location ~* /\.ht {
        return 404;
    }

    # Image not found replacement
    location ~* \.(jpe?g|png|gif|webp)$ {
        log_not_found off;
        error_page 404 /content/images/system/default/404.gif;
    }

    # CORS header (avoids font rendering issues)
    location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
        add_header Access-Control-Allow-Origin "*";
    }

    # PHP front controller
    location / {
        index index.php;
        try_files $uri $uri/ /index.php$is_args$query_string;
    }

    # Single PHP-entrypoint (disables direct access to .php files)
    location ~* \.php$  {
        internal;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}

但是当我去http://www.postimg.cz它不会重定向到https://postimg.cz为什么会这样?你能帮我吗?

服务器:Ubuntu 服务器 20.04

编辑//也试过这个,也不起作用:

server {
    listen 80;
    server_name www.postimg.cz postimg.cz;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name www.postimg.cz;
    ssl_certificate /etc/letsencrypt/live/www.postimg.cz/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.postimg.cz/privkey.pem;
    return 301 https://postimg.cz$request_uri;
}

server {
    listen 443 ssl;

    server_name postimg.cz;
ubuntu http nginx https
  • 1 个回答
  • 175 Views
Martin Hope
Pēteris Caune
Asked: 2022-03-03 08:00:53 +0800 CST

当主机头包含冒号字符时,NGINX 路由到错误的虚拟主机

  • 0

我的 nginx.conf 有几个“服务器”部分和一个包罗万象的服务器部分。这是一个示例 nginx.conf 给你一个想法:

user www-data;
worker_processes auto;
worker_cpu_affinity auto;
pid /run/nginx.pid;

events {
    worker_connections 4000;
    use epoll;
    accept_mutex off;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    error_log /var/log/nginx/error.log;

    server {
        listen 80;

        server_name foo.com;

        location / {
            default_type text/plain;
            return 200 "hello from foo.com";
        }

        error_page 500 502 503 504 /500.html;
    }

    server {
        listen 80 default_server;
        server_name _;

        location / {
            return 403 "sorry";
        }
    }

}

如果“主机”标头不是“foo.com”,我希望服务器返回 403。

显然有人在我的服务器上运行 Burp Suite,当他们发送“Host: foo.com:more-stuff-here”标头时,我注意到一个有趣的行为:NGINX 将请求路由到第一个“服务器”部分。它看起来好像忽略了标头值中的冒号及其后面的所有内容。

我可以使用上面的 nginx.conf 在本地重现它:

$ curl -H "Host: foo.com" http://127.0.0.1
hello from foo.com

$ curl -H "Host: foo.com:unexpected-content" http://127.0.0.1
hello from foo.com

$ curl -H "Host: bar.com" http://127.0.0.1
sorry

为什么 NGINX 会这样做?这是预期的行为吗?我应该在 nginx.conf 中进行哪些更改以确保带有“Host: foo.com:more-stuff-here”标头的请求转到默认块?

更新:对于研究同一问题的任何人,我还在NGINX 问题跟踪器中创建了一张票。

http nginx
  • 3 个回答
  • 420 Views
Martin Hope
Peedy
Asked: 2022-02-18 11:51:45 +0800 CST

haproxy:关闭或更改统计页面的 80 端口

  • 0

http-port 必须可用于其他用途。
统计页面的 80 端口必须关闭或移动到另一个端口。在该部分中
删除会禁用该页面。 返回 '​​0' -> 端口 80 已经可以访问。mode httpdefaultecho >/dev/tcp/hostname/80

http port configuration stats haproxy
  • 2 个回答
  • 198 Views
Martin Hope
ByteEater
Asked: 2022-02-10 04:18:53 +0800 CST

服务器可以提供多个 TLS 证书吗?

  • 1

假设我有一个域的 TLS 证书,但我不确定是否所有可能通过 HTTP 连接的用户代理都会接受它。我能否获得另一个证书,由另一个证书颁发机构签名,并在这种情况下作为后备使用,对用户透明?如果可能,建立安全连接的客户端-服务器通信将如何进行?这个用例在流行的 HTTP 服务器的配置中是否广为人知并受支持?

我知道有类似的问题,但他们询问通过子域(可能)或路径前缀(不可能的 IIUC,因为在协商时服务器只知道权限,而不是完整的请求 URI)来改变使用的证书。

http web-server ssl configuration certificate
  • 1 个回答
  • 111 Views
Martin Hope
sealionuss
Asked: 2022-02-06 05:46:29 +0800 CST

在同一主机和同一端口上的 NGINX 中使用多个服务器块

  • 1

我想配置服务器,以便服务器的根目录提供一些静态文件,这些文件是特定的端点,/nextcloud 为同一域上的 nextcloud 提供服务。

这是我的 nginx.conf -

worker_processes  8;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80 http2;
        listen [::]:80 http2;
        server_name  localhost;
        root   /srv/http/;
        location / {
            index  index.html index.php;
            try_files $uri $uri/ =404;
            autoindex on;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
    include /etc/nginx/sites-enabled/*;
}

这是我的 /etc/nginx/sites-enabled/nextcloud.conf

upstream php-handler {
    server unix:/run/nextcloud/nextcloud.sock;
}

server {
    listen 80;
    listen [::]:80;
    server_name nextcloud;

    root /usr/share/webapps/;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ^~ /.well-known {
        location = /.well-known/carddav { return 301 /nextcloud/remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /nextcloud/remote.php/dav/; }

        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

        return 301 /nextcloud/index.php$request_uri;
    }

    location ^~ /nextcloud {
        client_max_body_size 512M;
        client_body_timeout 300s;
        fastcgi_buffers 64 4K;

        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

        add_header Referrer-Policy                      "no-referrer"   always;
        add_header X-Content-Type-Options               "nosniff"       always;
        add_header X-Download-Options                   "noopen"        always;
        add_header X-Frame-Options                      "SAMEORIGIN"    always;
        add_header X-Permitted-Cross-Domain-Policies    "none"          always;
        add_header X-Robots-Tag                         "none"          always;
        add_header X-XSS-Protection                     "1; mode=block" always;

        fastcgi_hide_header X-Powered-By;

        index index.php index.html /nextcloud/index.php$request_uri;

        location = /nextcloud {
            if ( $http_user_agent ~ ^DavClnt ) {
                return 302 /nextcloud/remote.php/webdav/$is_args$args;
            }
        }

        location ~ ^/nextcloud/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)    { return 404; }
        location ~ ^/nextcloud/(?:\.|autotest|occ|issue|indie|db_|console)                  { return 404; }

        location ~ \.php(?:$|/) {
            rewrite ^/nextcloud/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /nextcloud/index.php$request_uri;

            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            set $path_info $fastcgi_path_info;

            try_files $fastcgi_script_name =404;

            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $path_info;

            fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
            fastcgi_param front_controller_active true;     # Enable pretty urls
            fastcgi_pass php-handler;

            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;

            fastcgi_max_temp_file_size 0;
        }

        location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite)$ {
            try_files $uri /nextcloud/index.php$request_uri;
            expires 6M;         # Cache-Control policy borrowed from `.htaccess`
            access_log off;     # Optional: Don't log access to assets

            location ~ \.wasm$ {
                default_type application/wasm;
            }
        }

        location ~ \.woff2?$ {
            try_files $uri /nextcloud/index.php$request_uri;
            expires 7d;         # Cache-Control policy borrowed from `.htaccess`
            access_log off;     # Optional: Don't log access to assets
        }

        location /nextcloud/remote {
            return 301 /nextcloud/remote.php$request_uri;
        }

        location /nextcloud {
            try_files $uri $uri/ /nextcloud/index.php$request_uri;
        }
    }
}

问题是这个配置不起作用。使用此配置,当我尝试访问 /nextcloud/ 时得到 404。

如果我在 nginx.conf 中禁用静态文件服务器块,我可以访问 /nextcloud/,但是我无法访问我的静态文件。如何配置使两者都在同一主机和同一端口上工作?

linux http nginx reverse-proxy nextcloud
  • 1 个回答
  • 3177 Views
Martin Hope
PierreJ
Asked: 2021-12-22 01:01:21 +0800 CST

假设平台性能基于 Nginx - ngx_http_stub_status_module

  • 0

Nginx 被放置在我们没有任何洞察力的微服务架构的前面。我们检索由http 存根状态公开的指标,并想计算平台性能的指标:我们不能在负载测试中使用延迟,因为我们想比较地理位置不同的站点。

到目前为止,我们尝试了什么:

  • 计算每单位时间总请求的增量。问题:它不反映性能,所有站点处理相同的请求量(每 100 毫秒 100 个请求)
  • 使用等待连接量规*

*使用此指标,我们观察到不同的行为。两个极端是:

2012服务器(E5-2620 v1,24线程):平均每100ms有68,62个等待连接

2021 服务器(AMD EPYC 7642,96 线程):平均每 100 毫秒 91,96 个等待连接

第一个问题。似乎应该将仪表读取为“越高越好”。为什么?该文档没有提供详细信息,但据我们所知,此处应出现等待答案的连接。或者这个量表是否仅由空闲连接组成(即已经服务的连接)?

第二个问题。在相同的负载测试中,最新服务器上接受/处理的连接指标要高得多(大约两倍)。为什么?两者都服务于由 100 个连接池发送的相同数量的请求。我们看到的是,处理的连接数量在开始时进展非常迅速,根据架构达到不同的上限,之后进展非常线性。我们无法在此图上找到对此行为的任何解释:已处理连接图

performance http load-balancing nginx load-testing
  • 1 个回答
  • 51 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve