ERROR: Invalid HTTP_HOST header: '/webapps/../gunicorn.sock'

后端 未结 2 590
清歌不尽
清歌不尽 2020-12-10 03:26

After I deployed my Django App last night I got tons of strange Emails saying:

ERROR: Invalid HTTP_HOST header: \'/webapps/example_com/run/gunicorn.sock


        
相关标签:
2条回答
  • 2020-12-10 03:31

    I found the answer to my my question in a django bug report.

        proxy_set_header Host $http_host;
    

    has to be replaced with:

        proxy_set_header Host $host;
    

    to make nginx pass the correct headers from that on instead of the gunicorn socket the requested page was in the django alerts.

    0 讨论(0)
  • 2020-12-10 03:33

    This person explains a bit more what is going on based on this very same post. Here's his/her explanation:

    ...when a request is made to the server and the HTTP Host is empty, nginx sets the HTTP host to the gunicorn sock.

    I can generate this error using curl:

    curl -H "HOST:" MY_DOMAIN_NAME -0 -v
    

    This sends a request without a HTTP Host. The -0 causes curl to use HTTP version 1.0. If you do not set this, the request will use HTTP version 1.1, which will cause the request to be rejected immediately and not generate the error.

    The solution is to replace $http_host with $host (as pointed out on Stackoverflow). When HTTP Host is missing, $host will take on the value of the “server_name” directive. This is a valid domain name and is the one that should be used.

    0 讨论(0)
提交回复
热议问题