如何在python中连接nginx proxy_pass到aiohttp webserver(错误)



我试图连接我的nginx proxy_pass到我的aiohttp web服务器但是我总是出错

这是我的Nginx配置:

server {
server_name www.example.com;
location /nextpay {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_buffering off;
proxy_pass https://127.0.0.1:5001;
}
}

下面是我的代码:

from aiohttp import web
from aiohttp.web_request import Request
WEB_SERVER_HOST = "127.0.0.1"
WEB_SERVER_PORT = 5001
Router = web.RouteTableDef()
@Router.get('/nextpay')
async def verify(request: Request):
print(type(request))
return web.Response(text="Hello, world")
def main():
app = web.Application()
app.add_routes(Router)
web.run_app(app, host=WEB_SERVER_HOST, port=WEB_SERVER_PORT)
if __name__ == "__main__":
main()

这是我每次请求/nextpay时得到的错误:

aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"

问题是我使用https而不是http:

server {
server_name www.example.com;
location /nextpay {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://127.0.0.1:5001;
}
}

相关内容

  • 没有找到相关文章

最新更新