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 / 问题 / 924373
Accepted
jdog
jdog
Asked: 2018-08-01 20:14:30 +0800 CST2018-08-01 20:14:30 +0800 CST 2018-08-01 20:14:30 +0800 CST

然后用 Apache for Cloudfront 重写 Basic Auth

  • 772

我有一个网站,所有页面都通过 AWS Cloudfront(现在 TTL 为 0)。

站点域是 www.example.com,它是云端分发的 CNAME。然后,Cloudfront 使用 origin.www.example.com 从我的 Web 服务器请求该站点,并为身份验证添加自定义标头。

但是现在我还需要将基本身份验证添加到站点,直到它启动。我已经通过在 RewriteCond 中使用 LA-U:REMOTE_USER 进行了尝试

此配置有效,但没有 Auth:

<VirtualHost *:80>

    ServerName www.example.com
    ServerAlias www.example.com

    ServerAdmin [email protected]

    DocumentRoot /var/www/www.example.com/trunk

    <IfModule mpm_itk_module>
        AssignUserId www_site www_site
    </IfModule>

    <LocationMatch "^(.*\.php)$">
        ProxyPass fcgi://127.0.0.1:9154/var/www/www.example.com/trunk
    </LocationMatch>

    Alias "/robots.txt" "/var/www/norobots.txt"

    <Directory /var/www/www.example.com>
        RewriteEngine on
        RewriteCond  %{HTTP:X-PSK-Auth}  !^mypassword$
        RewriteRule  .* - [F]
    </Directory>

    CustomLog /var/www/www.example.com/apachelogs/www.example.com-access.log combined
    ErrorLog /var/www/www.example.com/apachelogs/www.example.com-error.log

</VirtualHost>
curl http://cxcglobal.demonow.website/

返回站点 HTML。还

curl --header "X-PSK-Auth:mypassword" "http://cxcglobal.demonow.website/

返回站点源代码。

但是,当我将配置修改为

<VirtualHost *:80>

    ServerName www.example.com
    ServerAlias origin.www.example.com

    ServerAdmin [email protected]

    DocumentRoot /var/www/www.example.com/trunk

    <IfModule mpm_itk_module>
        AssignUserId www_site www_site
    </IfModule>

    <LocationMatch "^(.*\.php)$">
        ProxyPass fcgi://127.0.0.1:9154/var/www/www.example.com/trunk
    </LocationMatch>

    Alias "/robots.txt" "/var/www/norobots.txt"

    <Directory /var/www/www.example.com>
        RewriteEngine on
        RewriteCond  %{HTTP:X-PSK-Auth}  !^mypassword$
        RewriteRule  .* - [F]

        RewriteCond %{LA-U:WxLaRwvCQ2yAf5KJREMOTE_USER} !^$
        RewriteRule ^/(.*) http://origin.www.example.com/$1   [P,L]

        AuthUserFile /etc/apache2/staging.passwd
        AuthType Basic
        AuthName "Review security udpates"
        Require valid-user

        LogLevel alert rewrite:trace3

    </Directory>

    CustomLog /var/www/www.example.com/apachelogs/www.example.com-access.log combined
    ErrorLog /var/www/www.example.com/apachelogs/www.example.com-error.log

</VirtualHost>

我收到一个错误:

curl http://www.example.com/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at origin.www.example.com Port 80</address>
</body></html>

对于两个 curl 请求。我在特定于站点的错误日志中没有错误,在全局 apache 错误日志中也没有错误。我也找不到重写日志的任何条目。

rewrite
  • 1 1 个回答
  • 690 Views

1 个回答

  • Voted
  1. Best Answer
    user1751825
    2018-08-02T00:05:30+08:002018-08-02T00:05:30+08:00

    更好的方法,可能是使用 lambda 直接在云端处理身份验证......

    我自己没有尝试过,但我找到了这个资源......

    http://engineering.widen.com/blog/AWS-CloudFront-User-Authentication-using-Lambda@Edge/

    它似乎相对简单。Lambda@Edge 允许您运行代码来检查和修改传入请求。

    • 0

相关问题

  • 阿帕奇虚拟主机

  • IIS 7 中的 URL 重写

  • IIS7 请求跟踪日志上的 URL_CHANGED 事件是什么?

  • 如何强制我的网址始终以 www 开头?

  • mod_rewrite 不转发 GET 参数

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