Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

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

I'm sure this is somehow related to the following nginx config:

upstream example_app_server {
  server unix:/webapps/example_com/run/gunicorn.sock fail_timeout=0;
}

server {

    listen   80;
    server_name example.com;

    client_max_body_size 4G;

    access_log /webapps/example_com/logs/nginx-access.log;
    error_log /webapps/example_com/logs/nginx-error.log;


    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;

        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://example_app_server;
            break;
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...