【问题标题】:How to allow for encoded slashes in an Elastic Beanstalk Load Balancer environment如何在 Elastic Beanstalk 负载均衡器环境中允许编码斜杠
【发布时间】:2016-12-13 10:08:18
【问题描述】:

我遇到了一个问题,即传递给我的 Elastic Beanstalk 环境的某些 URL 在 URL 的参数中包含斜杠,例如:

https://example.com/param1=this/that/param2=....

这些 URL 在我的应用程序可以在本地测试中正确处理斜线的上下文中有效。在 EB 上的生产中,Apache 服务器 EB 用作默认解码斜杠,导致 404 返回给用户。我对我的 Apache 知识不是很了解。在环境启动时动态设置参数的最佳和最有效方法是:AllowEncodedSlashes NoDecode 在我的 Apache 配置中?

显然,通过 SSH 连接到我的实例以进行更改远非理想,并且不会持续超过重新加载。是否可以以某种方式使用我的应用程序 .ebextensions 进行设置?

编辑:

为了提供更多详细信息,我正在使用负载平衡的 EB 环境,该环境使用 HTTPS 并正在运行 Django 应用程序(使用 mod_wsgi)

这是我的 wsgi.conf 文件,取自我的一个实例:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/baselinenv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On

<VirtualHost *:80>

Alias /static/ /opt/python/current/app/static/
<Directory /opt/python/current/app/static/>
Order allow,deny
Allow from all
</Directory>


WSGIScriptAlias / /opt/python/current/app/test_app/wsgi.py

AllowEncodedSlashes NoDecode

<Directory /opt/python/current/app/>
  Require all granted
</Directory>

WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \
  python-path=/opt/python/current/app:/opt/python/run/venv/lib64/python3.4/site-packages:/opt/python/run/venv/lib/python3.4/site-packages user=wsgi group=wsgi \
  home=/opt/python/current/app
WSGIProcessGroup wsgi
</VirtualHost>

LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b     \"%{Referer}i\" \"%{User-Agent}i\"" combined

这是我必须编辑的文件吗? EB enviornemnt 不会在环境重启时覆盖我的更改吗?

【问题讨论】:

标签: apache amazon-web-services url amazon-elastic-beanstalk


【解决方案1】:

检查下面的 Apache 示例配置以处理编码斜杠。请记住,这只是一个示例。您必须通过参考以下代码来操作您的 Apache 代码,因为您没有将 apache 主机文件粘贴到您的问题中。

<VirtualHost *:80>
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass / http://localhost:8080/ retry=0
  ProxyPassReverse / http://localhost:8080/
  ProxyPreserveHost on
  AllowEncodedSlashes NoDecode
  LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
  ErrorLog /var/log/httpd/elasticbeanstalk-error_log
  TransferLog /var/log/httpd/elasticbeanstalk-access_log
</VirtualHost>

【讨论】:

  • 我的问题是,我如何有效地进行这些更改?我是否将我的 EB 实例中的 wsgi.conf 文件替换为类似版本?
  • 在 AllowEncodedSlashes 行上方添加此 ProxyPreserveHost
猜你喜欢
  • 1970-01-01
  • 2014-02-11
  • 2019-04-21
  • 2019-01-24
  • 2013-08-10
  • 2017-02-14
  • 1970-01-01
  • 2019-09-02
  • 2020-11-21
相关资源
最近更新 更多