gunicorn 解决log为127.0.0.1问题

0.修改gunicorn -log格式

gunicorn -w 2 -b 127.0.0.1:8001 test:app --access-logfile='-' --access-logformat='%({x-forwarded-for}i)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'

1.nginx添加proxy header

      upstream backend {
        server 127.0.0.1:8001;
        server 127.0.0.1:8002;
      }

    server{
      listen 8000;
      server_name localhost;
      client_max_body_size 10m;

      location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $http_host;
      # we don't want nginx trying to do something clever with
      # redirects, we set the Host: header above already.
      proxy_redirect off;
        proxy_pass http://backend;
      }
    }

posted @ 2022-04-13 09:16  烧刘病  阅读(171)  评论(0编辑  收藏  举报
回到页首