Django API 在本地工作,但在 Elastic Beanstalk 上部署时不起作用 [英] Django API works locally but not when deployed on Elastic Beanstalk

查看:27
本文介绍了Django API 在本地工作,但在 Elastic Beanstalk 上部署时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Django Rest FrameworkDjango Rest Framework JWT,但我遇到了关于本地行为与外部行为的问题.

I'm working with Django Rest Framework and Django Rest Framework JWT, but I'm running into an issue in regards to local behavior vs external behavior.

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

When I make a POST request to get a JWT token, everything works as desired both locally and on my EC2 instance. However, once I have the token, when I make a request to my server that requires authentication, only my local server returns the expected response. On my deployed server, I get the following error:

{"detail":"未提供身份验证凭据."}

到目前为止我尝试过的:

What I've tried so far:

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

Editing http.conf by sshing into my server and enabling WSGIPathAuthorization. (saw a similar post here and tried the solution)

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

What could be causing this behavior? My local machine and my deployed code are identical, leading me to believe that this has something to do with server-side configuration.

感谢所有帮助.谢谢!

推荐答案

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

Simply restarting Apache after enabling WSGPPathAuthorization fixed my error. For those of you who encounter something similar, here's what I did:

  1. SSH 到服务器

  1. SSH into the server

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

Navigate to where your http.conf file is stored (in Apache, this is usually etc/httpd/http.conf)

编辑http.conf,添加WSGIPathAuthorization On.

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

Restart Apache by running sudo service httpd restart.

这篇关于Django API 在本地工作,但在 Elastic Beanstalk 上部署时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆