本文介绍了错误:HTTP_HOST标头无效:'/webapps/../gunicorn.sock'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 错误:无效的HTTP_HOST标头:p /webapps/example_com/run/gunicorn.sock 

我确定这与以下有关nginx config:

 上游example_app_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主机$ http_host;

proxy_redirect关闭;

if(!-f $ request_filename){
proxy_pass http:// example_app_server;
break;
}
}
}


解决方案

我在django错误报告中找到了我的问题的答案。

  proxy_set_header Host $ http_host; 

必须替换为:

  proxy_set_header Host $ host; 

使nginx通过正确的标头,而不是所请求的页面在django警报。


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;
        }
    }
}
解决方案

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.

这篇关于错误:HTTP_HOST标头无效:'/webapps/../gunicorn.sock'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 04:05