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 / 问题

问题[apache2](server)

Martin Hope
Ami Heines
Asked: 2024-12-17 15:55:09 +0800 CST

如果主机标头与 Apache 中的请求 URL 不同,如何拒绝主机标头?

  • 7

我有一个 Apache/2.4.6 (CentOS) 服务器,其中有多个子域作为 Apache VirtualHost 中的 ServerAlias。

类似于:

<VirtualHost *:443>
  ServerName mydomain.com
  ServerAlias a.mydomain.com
  ServerAlias b.mydomain.com

每个客户公司都应通过其子域进行访问,并且为了安全起见,每个客户公司都有不同的数据库,数据是分离的。

一位网络安全专家提醒我,存在一个漏洞,一个子域“a.mydomain.com”的用户可以通过在从客户端到 Web 服务器的调用中添加 Host 标头来访问另一个子域“b.mydomain.com”。

一开始我尝试用 PHP 获取信息,但失败了,PHP 没有获取到 headers 信息。然后我转而寻找在 Web 服务器级别(Apache)上解决此问题的方法。

当恶意用户试图欺骗服务器并使用主机头将请求发送到另一个子域时,我想要检测并拒绝,在此示例中,用户应该由 a.mydomain.com 而不是 b.mydomain.com 提供服务:

curl 'https://a.mydomain.com/users/login' \
  -H 'Host: b.mydomain.com' \
  --data-raw $'{"email":"[email protected]","password":"*****"}'

来自客户端应用程序的正常调用如下所示:

curl 'https://a.mydomain.com/users/login' \
  --data-raw $'{"email":"[email protected]","password":"*****"}'

我尝试过RequestHeader unset host,但是它并没有像我预期的那样工作。

我的预期是,如果恶意用户发送了“Host”标头,服务器应该会忽略它。这将导致上述两个 culr 调用实际上相同。

我认为发生的情况是 Apache 在调用中使用了 URL,但是如果存在“Host”标头,则它将优先使用并且使用该标头,而 URL 中的原始域将被丢弃。

如果是这种情况,则RequestHeader unset host不会向我的 PHP 代码发送任何主机,这会导致我的代码中断,因为它需要知道哪个客户公司正在调用它。

apache2
  • 2 个回答
  • 271 Views
Martin Hope
TRiG
Asked: 2024-09-10 21:36:22 +0800 CST

在 Apache 配置中,重定向或重写规则是否优先?

  • 5

我希望 Apache 上的域名纯粹作为重定向存在。为此,我创建了/etc/apache2/sites-available/redirect.example.info.conf以下内容:

<VirtualHost *:80>
    ServerName redirect.example.info
    ServerAdmin webmaster@localhost
    Redirect / https://example.com/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

当我运行的时候certbot --apache,它被重写为:

<VirtualHost *:80>
    ServerName redirect.example.info
    ServerAdmin webmaster@localhost
    Redirect / https://example.com/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =redirect.example.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

/etc/apache2/sites-available/redirect.example.info-le-ssl.conf并创建一个新文件:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName redirect.example.info
    ServerAdmin webmaster@localhost
    Redirect / https://example.com/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/ca-webs.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ca-webs.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

这确实按预期工作。重定向运行http://redirect.example.info→ https://redirect.example.info→ https://example.com。但我不清楚它是如何工作的。重写的文件既有Redirect命令,又有RewriteRule命令,我本以为Redirect(先来)会优先。这个文件实际上是如何评估的?

apache2
  • 1 个回答
  • 25 Views
Martin Hope
inersha
Asked: 2024-06-12 04:38:35 +0800 CST

使用 Apache 实现速率限制的最佳方法是什么?

  • 5

我正在运行 Apache 网络服务器,我想为每个单独的 IP 地址添加一些简单的速率限制。

我目前收到似乎有很多机器人请求访问网站,这稍微减慢了正常请求的速度。

我希望能够添加速率限制以减慢机器人的速度,同时又不妨碍 googlebot 的抓取。我猜大约每个 IP 每小时 20,000 个请求应该可以做到这一点,可能更少。

无论如何,为 Apache 添加速率限制的最简单的方法是什么?

到目前为止我发现了几个选择:

  • mod_security
  • mod_evasive
  • mod_ratelimit
  • mod_limitpconn

但似乎没有一个明确的、明显的解决方案。

或者,使用 Nginx 作为反向代理(并使用内置的速率限制)似乎是另一个可行的选择。它看起来比我迄今为止为 Apache 找到的更容易实现。尽管如果我缺少一个简单的解决方案,我更愿意只使用 Apache。

Fail2Ban 似乎是另一个简单的解决方案,但我不确定429当访问者达到速率限制时是否可以使用它来返回响应代码。

你会推荐什么?

apache2
  • 1 个回答
  • 116 Views
Martin Hope
sKling
Asked: 2024-04-22 16:26:52 +0800 CST

Apache - 将 www 和非子域重定向到同一页面,而不会在 TYPO3 中出现 404

  • 6

所以我遇到以下问题:当我使用https://www.example.com作为域时,我得到内容,但是当我使用https://example.com时,我得到通用 TYPO3 404 错误页面。

我尝试设置一个重定向,其中 example.com 和 .* 作为源路径,我的起始页作为目标,我还尝试在站点配置中设置 baseVariants。有点奇怪的是,我的正常基地只是 example.com 而不是www.example.com但www.example.com是正在工作的,而另一个只是给出 404。

我需要可靠地将https://example.com和https://example.com配置为获得相同的页面。

我在带有 Apache Web 服务器和 PHP 8.1 的 Ubuntu 22.04.4 上使用 TYPO v12.4.14

[这是我尝试使用重定向的方法。但这不起作用,因为正则表达式没有分隔符。至少这是我最初发表这篇文章以来学到的] 1

编辑2:我尝试制作2个虚拟主机将 example.com 重定向到www.example.com。这是我的配置文件:

文件1 example.conf:

<VirtualHost *:80>

    ServerName example.com
    ServerAdmin [email protected]
    Redirect permanent / https://www.example.com

</VirtualHost>

文件 2 示例-ssl.conf

<VirtualHost *:443>

    ServerName example.com
    ServerAdmin [email protected]
    Redirect permanent / https://www.example.com

</VirtualHost>

现在它适用于 http:// 示例。com 但不适用于 https:// 示例。com

注意:我之前在堆栈溢出时问过这个问题,并将其复制到此处。

这是我的默认配置 000-default-le-ssl.config

<IfModule mod_ssl.c>
<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    # ServerName example.com

    ServerAdmin [email protected]
    DocumentRoot "/var/www/Example/public/"

    <Directory "/var/www/Example/public">
         Options Indexes FollowSymLinks MultiViews
     AllowOverride All
     Order allow,deny
     allow from all
    </Directory>


    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf



Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    Redirect permanent / https://www.example.com/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf


</VirtualHost>

apache2
  • 1 个回答
  • 36 Views
Martin Hope
SCMedia
Asked: 2024-01-18 20:45:53 +0800 CST

Ubuntu 22.04 上的 Apache 升级到 2.4.58

  • 5

我正在尝试在运行 Ubuntu 22.04 的 Digital Ocean 上将 apache 从 2.4.52 升级到 2.4.58。我的升级路径是:

sudo apt update

进而:

sudo apt install apache

但我收到一条消息说

apache2 is already the newest version (2.4.52-lubuntu4.7)

apache2
  • 2 个回答
  • 39 Views
Martin Hope
Marc
Asked: 2023-11-18 18:47:50 +0800 CST

Apache 默认 Conf 主机绑定

  • 6

我在 Ubuntu 上安装了标准的 apache2,其中添加了 mysite1.com,其中包含以下内容:

 <VirtualHost mysite1.com:80>

自从添加此功能后,当我致电时,http://<external-ip>我不再获得在以下位置配置的默认 Apache 站点/etc/apache2/sites-enabled/000-default.conf:

 <VirtualHost *:80>

为什么要http://<external-ip>绑定到 mysite.com?

我希望所有未配置的Host:标头都达到默认值,并且<external-ip>在我看来,未配置。

更新:@Daniel Ferradal 提供的解决方案是在所有块中仅使用通配符<VirtualHost *:80>并使用ServerName指令进行主机名映射。

apache2
  • 1 个回答
  • 52 Views
Martin Hope
German Online Publisher
Asked: 2023-10-23 06:50:34 +0800 CST

从自己的域创建的奇怪反向链接

  • 5

在 Ahrefs 中,我注意到,我的一个网页有奇怪的(数千个)反向链接,这些反向链接来自四个自己的域(以及来自我自己的专用服务器的一个 IP)。

例如:这个URL(这是可疑的)

https://florida-paintings.art/industrie/verbindungstechnik/kleben/10314-dosierung-von-1k-acrylatklebstoff-mit-komplexen-dichtraupengeometrien

是这个的反向链接:

https://www.developmentscout.com/industrie/messtechnik/11934-caq-system

另一个例子:这个 URL(这是可疑的)

https://51.89.98.21/branche/gebaeudetechnik/11720-smart-panel-okw-gehaeuse

是这个的反向链接:

https://www.developmentscout.com/branche/mobile-arbeitsmaschine/11919-profi-drohne

奇怪的是,所有可疑的 URL 都有一个规范标签,而不是“正确”的标签,而是一个对其自己的 URL 的自引用标签。

我的域名的管理是通过OVH的DNS服务器实现的。

我不知道“谁”(CMS Joomla、Debian、ISP 等)正在生成所有这些 URL。因此,如果有人有想法,我将非常感激!

谢谢詹斯

apache2
  • 2 个回答
  • 111 Views
Martin Hope
craigmj
Asked: 2023-10-11 23:18:21 +0800 CST

带有 mod_http2 的 Apache 是否容易受到 Http/2 快速重置 CVE-2023-44487 的影响

  • 8
这个问题是从 Webmasters Stack Exchange 迁移的,因为它可以在服务器故障上得到回答。4 天前迁移 。

我在 apache 网站上找不到任何有关此内容的信息,因此我禁用了 http/2 作为预防措施。有关如何保护 Apache2 免受此影响的任何信息吗?

apache2
  • 1 个回答
  • 1099 Views
Martin Hope
John
Asked: 2023-08-18 01:19:28 +0800 CST

为什么我的浏览器显示 Content-Type 行?

  • 5

按照此处描述的内容 --- https://httpd.apache.org/docs/2.4/howto/cgi.html --- 我创建了一个小型 Perl 文档:

#!/usr/bin/perl
print "Content-Type: text/html; charset=utf-8\n\n";
print "Hello, World.";

并称之为first.pl。我也修改了它,使它看起来像

#!/usr/bin/perl
print "Content-Type: text/html; charset=utf-8\r\n\r\n";
print "Hello, World.";

因为有朋友指出“\n”的含义与系统有关,要求的是CR-LF CR-LF,但结果是一样的。)

当我从 Chrome 浏览器查看时,localhost/~mylogin/first.pl我得到以下输出:

Content-Type: text/html; charset=utf-8

Hello, World.

(这个; charset=...内容是对 Apache 文档建议的内容的轻微修改,因为保留它也会产生 Content-Type 输出行,并且一些搜索表明字符集可能很重要。正如它所发生的那样,它没有什么区别。)

Apache 参考文档说“无论您将文件放在何处,您都会在浏览器窗口中看到这一行。” Hello, World.

显然,我看到两行,第一行应该仅被视为其余内容的描述,我认为这是一个问题。

我希望这是一些非常基本的错误,并且非常感谢任何建议。

语境

我的 Mac 运行的是 Monterey 12.6.6

我开始按照这里的说明进行操作。

从普通httpd.conf文件开始,我只做了一些编辑,取消注释以下内容:

LoadModule perl_module libexec/apache2/mod_perl.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf

在 中/etc/apache2/extra/httpd-userdir.conf,我取消了注释

Include /private/etc/apache2/users/*.conf

我创建了/etc/apache2/users/mylogin.conf,并为其提供了以下内容:

<Directory "/Users/mylogin/Sites/"> 
  AddLanguage en .en 
  AddHandler perl-script .pl 
  PerlHandler ModPerl::Registry 
  Options Indexes MultiViews FollowSymLinks ExecCGI 
  AllowOverride None 
  Require host localhost
</Directory>

我已经跑了

chmod +a "_www allow execute" ~

[当然,在上述所有情况下,我都将“mylogin”替换为我的实际登录名]

然后,按照 Apache 的指示,我将其添加到httpd.conf文件中:

<Directory "/Users/mylogin/Sites">
    Options +ExecCGI
    AddHandler cgi-script .cgi 
</Directory>
apache2
  • 2 个回答
  • 43 Views
Martin Hope
Jean
Asked: 2023-04-20 18:44:11 +0800 CST

ModSecurity:如何防止正文显示在 JSON 输出中?

  • 5

使用 Modsecurity,我将捕获的请求以 JSON 格式写入日志。body 字段对于我的 ELK 索引来说太冗长了,并且会产生很多解析错误。

我可以禁止正文出现在 JSON 日志中吗?

apache2
  • 1 个回答
  • 20 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