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 / 问题 / 731534
Accepted
igal
igal
Asked: 2015-10-26 10:24:57 +0800 CST2015-10-26 10:24:57 +0800 CST 2015-10-26 10:24:57 +0800 CST

在 Ubuntu 12.04 上检查 Apache 2.2 的健全性检查 mod_rewrite

  • 772

摘要:我正在测试一个简单的包罗万象的重写规则。它似乎没有生效,没有被记录,我也没有收到任何错误。


我是一名初级服务器管理员,试图更好地了解如何配置 Apache Web 服务器。现在我正在阅读一些文档并在 Ubuntu 12.04.5 LTS(Precise Pangolin)上试验 Apache/2.2.22。

我读过的一条建议是,使用 mod_rewrite 明确要求 HTTP/1.1 并拒绝 HTTP/1.0 请求是一个很好的策略。给出的示例代码如下:

RewriteEngine On
RewriteCond %{THE_REQUEST} !HTTP/1\.1$
RewriteRule .* - [F]

我尝试将此块添加到我的配置文件中:

/etc/apache2/conf.d/security

我还检查以确保 mod_rewrite 已启用并且没有其他冲突的重写规则,例如:

$ sudo a2enmod rewrite

>   Module rewrite already enabled

$ grep -Firl 'Rewrite' /etc/apache2/

>   /etc/apache2/conf.d/security
>   /etc/apache2/mods-enabled/rewrite.load
>   /etc/apache2/mods-available/rewrite.load

然后我重新启动 Apache 并使用 curl 测试了新配置:

curl --http1.0 127.0.0.1

不幸的是,我返回了默认的欢迎页面,而不是预期的 403 FORBIDDEN 响应。经过一番修改后,我最终得到了以下重写配置(在 /etc/apache2/conf.d/security 中):

RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3
RewriteCond %{THE_REQUEST} ^.*$
RewriteRule ^.*$ - [F]

我再次得到 Apache 默认欢迎页面,而不是预期的 403 FORBIDDEN 响应。这是一个示例会话,我在其中使用 curl 测试服务器,然后检查日志文件(重写、错误和访问日志):

$ sudo service apache2 restart

>   * Restarting web server apache2
>   ... waiting .                           [OK ]

$ curl 127.0.0.1

>   <html><body><h1>It works!</h1>
>   <p>This is the default web page for this server.</p>
>   <p>The web server software is running but no content has been added, yet.</p>
>   </body></html>

$ sudo tail -1 /var/log/apache2/rewrite.log

>

$ sudo tail -2 /var/log/apache2/error.log

>   [Sun Oct 25 18:13:13 2015] [notice] caught SIGTERM, shutting down
>   [Sun Oct 25 18:13:13 2015] [notice] Apache/2.2.22 (Ubuntu) configured -- resuming normal operations

$ sudo tail -1 /var/log/apache2/access.log

>   127.0.0.1 - - [25/Oct/2015:18:13:16 +0000] "GET / HTTP/1.1" 200 402 "-" "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3"

是什么赋予了?

apache-2.2
  • 1 1 个回答
  • 255 Views

1 个回答

  • Voted
  1. Best Answer
    igal
    2015-10-28T06:27:54+08:002015-10-28T06:27:54+08:00

    我在 Apache httpd 邮件列表 ([email protected]) 上收到了 Eric Covener 的答复,他告诉我重写规则不会被虚拟主机继承。

    Ubuntu Apache 安装预配置了一个包罗万象的默认虚拟主机,它没有继承重写设置。将相同的配置设置复制粘贴到虚拟主机主体中会导致预期的行为。

    再次查阅文档后(有了这个新见解),我注意到 mod_rewrite 参考中有关虚拟主机的以下部分:

    • http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#vhosts

    为了让给定的虚拟主机继承重写规则,该虚拟主机配置块的主体中​​需要以下指令:

    RewriteEngine On
    RewriteOptions Inherit
    
    • 0

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

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