how to connect nginx proxy_pass to aiohttp webserver in python (Error)

Viewed 72

Im trying to connect my nginx proxy_pass to my aiohttp web server But im keep getting errors

Here is my Nginx config:

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;
     }
}

And here is my code :

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()

And this is the error im keep getting every time i request on /nextpay :

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

The Problem was that i used https instead of 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;
     }
}
Related