【问题标题】:Django API works locally but not when deployed on Elastic BeanstalkDjango API 在本地工作,但在部署在 Elastic Beanstalk 上时不工作
【发布时间】:2018-12-31 11:45:01
【问题描述】:

我正在与Django Rest FrameworkDjango Rest Framework JWT 合作,但在本地行为与外部行为方面遇到了问题。

当我发出 POST 请求以获取 JWT 令牌时,本地和我的 EC2 实例上的一切都按预期运行。但是,一旦我有了令牌,当我向需要身份验证的服务器发出请求时,只有我的本地服务器返回预期的响应。在我的已部署服务器上,我收到以下错误:

{"detail":"Authentication credentials were not provided."}

到目前为止我已经尝试过:

编辑http.conf 通过ssh 进入我的服务器并启用WSGIPathAuthorization。 (看到一个类似的帖子here 并尝试了解决方案)

什么可能导致这种行为?我的本地机器和我部署的代码是相同的,这让我相信这与服务器端配置有关。

感谢所有帮助。谢谢!

【问题讨论】:

    标签: django amazon-web-services django-rest-framework jwt


    【解决方案1】:

    启用 WSGPPathAuthorization 后只需重新启动 Apache 即可修复我的错误。对于那些遇到类似情况的人,这就是我所做的:

    1. SSH 进入服务器

    2. 导航到您的 http.conf 文件的存储位置(在 Apache 中,这通常是 etc/httpd/http.conf)

    3. 编辑http.conf,添加WSGIPathAuthorization On

    4. 通过运行 sudo service httpd restart 重新启动 Apache。

    【讨论】:

      【解决方案2】:

      您提到了 ElasticBeanstalk。

      您可以将其添加到将在部署期间执行的容器命令中。

      01_wsgipass:
       command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'
      

      【讨论】:

        【解决方案3】:

        当您在 EC2 实例上使用 apache 配置 wsgi 时,通常会出现此问题。 基本上是apache配置中的问题, 它与 AWS EC2 无关。 由于默认情况下 apache 不处理 Authorization 标头,因此为了实现这一点,我们需要配置其文件。 对于ubuntu

        cd /etc/apache2/apache2.conf
        

        粘贴以下行

        WSGIPassAuthorization On
        

        【讨论】:

          猜你喜欢
          • 2016-02-18
          • 1970-01-01
          • 2016-06-20
          • 1970-01-01
          • 1970-01-01
          • 2021-05-22
          • 2016-01-08
          • 2020-09-24
          • 1970-01-01
          相关资源
          最近更新 更多