我目前正在Amazon Elastic Beanstalk上运行Python Flask应用程序。当我测试应用程序时,它在本地工作正常(我使用Postman发送GET和POST请求)。但是,在AWS上,它不起作用,因为到达我的EC2实例(在负载均衡器后面)的请求不包含授权标头。似乎负载平衡器剥离了标头。我在这里做错了吗?
这是我在本地和Elastic Beanstalk上打印标题时所得到的对比。
本地
[2017-07-04 13:18:14,650] [INFO] [common.decorators] Headers = Host: localhost:5000
Connection: keep-alive
Content-Length: 151
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Cache-Control: no-cache
Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Content-Type: application/json
Authorization: Bearer ad9fd4d9-6ce6-497b-855a-dcebebdad65b
Postman-Token: xxxxx
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Elastic Beanstalk:
[2017-07-04 17:27:03,813] [DEBUG] [common.decorators] Headers = Accept-Language: en-US,en;q=0.8
Accept: */*
Host: dev.onetext.com
X-Forwarded-For: 66.30.13.108
Content-Type: application/json
Postman-Token: xxxxx
Connection: keep-alive
Accept-Encoding: gzip, deflate, sdch, br
X-Forwarded-Proto: https
Cache-Control: no-cache
X-Forwarded-Port: 443
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
答案 0 :(得分:3)
感谢@notionquest添加的评论,我在https://forums.aws.amazon.com/thread.jspa?messageID=729128
找到了解决方案我通过在.ebextensions文件夹下添加一个包含以下内容的新文件解决了这个问题:
files:
"/etc/httpd/conf.d/wsgihacks.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIPassAuthorization On
答案 1 :(得分:1)
AWS在标题中不接受(_)的非下划线,尽管我们可以使用(-),所以从标题变量中删除下划线 ,例如: header_var_val =“某些值” 替换为
headervarval = "some value"
对我有用