首页 > 解决方案 > 我的 Nginx,每 2 次尝试执行一次 proxy_pass

问题描述

这是我将请求反向/nt到另一个应用程序的 Nginx 代码。但它仅在每 2 次尝试时有效:

events {

  worker_connections 32000;
  use epoll;
  accept_mutex on;
  multi_accept on;
}

http {

  include mime.types;
  default_type application/octet-stream;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  reset_timedout_connection on;
  gzip off;
  access_log off;
  keepalive_timeout 0;
  client_max_body_size 20m;

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  ssl_prefer_server_ciphers on;

  access_log /var/log/openresty/access.log;
  error_log /var/log/openresty/error.log;

  real_ip_header X-Forwarded-For;

  limit_conn_zone $binary_remote_addr zone=perip:5m;
  limit_req_zone $binary_remote_addr zone=one:5m rate=100r/s;
  limit_req_zone $binary_remote_addr zone=phplimit:10m rate=3r/s;

  server {

    listen 80 default_server;
    listen [::]:80 default_server;
    limit_conn perip 5;
    limit_req zone=one burst=20 nodelay;
    limit_req_status 444;
    limit_conn_status 444;
    root /usr/local/openresty/nginx/html/default;
    index index.html index.htm;

    location /nt {

      proxy_buffering off;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_connect_timeout 10;
      proxy_send_timeout 30;
      proxy_read_timeout 30;
      proxy_http_version 1.1;
      limit_req_status 444;
      proxy_pass http://$proxy;
    }
  }
}

这是在正确尝试时返回到应用程序的请求标头:

{ 
    host: 'NGONX REVERSE PROXY SERVER IP',
    'x-forwarded-for': 'CLIENT IP',
    connection: 'close',
    'cache-control': 'max-age=0',
    'upgrade-insecure-requests': '1',
    'user-agent':
     'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
    accept:
     'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'accept-encoding': 'gzip, deflate',
    'accept-language': 'en-US,en;q=0.9'
}

这是在错误尝试时返回到应用程序的请求标头:

{ 
    host: '127.0.0.1:3000', # MY APP URL
    connection: 'close',
    'cache-control': 'max-age=0',
    'upgrade-insecure-requests': '1',
    'user-agent':
     'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
    accept:
     'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'accept-encoding': 'gzip, deflate',
    'accept-language': 'en-US,en;q=0.9'
}

为什么会这样?

标签: nginxreverse-proxy

解决方案


推荐阅读