保留nginx中的响应头

时间:2016-01-28 11:06:49

标签: nginx reverse-proxy gunicorn

我有一个反向代理设置(我认为),用于运行猎鹰应用程序的gunicorn。我还能够在nginx服务器上设置SSL。 /etc/nginx/nginx.conf:

worker_processes 1;

user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # set to 'on' if nginx worker_processes > 1
}

http {
  include mime.types;
  # fallback in case we can't determine a type
  default_type application/json;
  access_log /tmp/nginx.access.log combined;
  sendfile on;
  gzip              on;
  gzip_http_version 1.0;
  gzip_proxied      any;
  gzip_min_length   500;
  gzip_disable      "MSIE [1-6]\.";
  gzip_types        application/json;

  upstream app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response
    server 127.0.0.1:6789 fail_timeout=0;
  }

  server {
    # if no Host match, close the connection to prevent host spoofing
    listen 80 default_server;
    return 444;
  }

  server {
    listen 443 ssl;
    client_max_body_size 4G;

    # set the correct host(s) for your site
    server_name 0.0.0.0;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    keepalive_timeout 2;

    location / {
      proxy_bind $server_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header Host $http_host;
      proxy_set_header   X-Real-IP $remote_addr;
      proxy_set_header   X-Forwarded-Host $server_name;
      proxy_redirect off;
      proxy_pass http://app_server;
    }
  }
}

我需要更改什么才能保留gunicorn的响应标头?另外,我对此完全陌生。那么有什么我应该改变的吗?

0 个答案:

没有答案