My Openresty, do proxy_pass once on every 2 attempt

29 views
Skip to first unread message

Amir Salar Pourhasan

unread,
Jul 16, 2019, 8:42:14 AM7/16/19
to openresty-en

This is my Nginx code that I revers request /nt to another app. But it only works once on every 2 attempt:


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;
   
}
 
}
}


This is request headers that revers to the app on correct attempt:


{
    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'
}


And This is request headers that revers to the app on incorrect attempt:


{
    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'
}


Why it is happening?

Reply all
Reply to author
Forward
0 new messages