3

I installed Nginx on an Ubuntu server 14.04 as a reverse proxy to redirect traffic coming to a single IP address to multiple NodeJs running on different ports. It also redirects HTTP to HTTPS.

Here's the content of nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 4096;
    multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

    # access_log /var/log/nginx/access.log;
    access_log off;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Here's the content of /sites-enabled/default:

server {
   listen 80;
   server_name *.domain.com;
   #redirect HTTP to HTTPS
   return 301 https://$host$request_uri;     
}

server {
   listen 443;
   server_name app.domain.com;
   ssl on;
   ssl_certificate /etc/ssl/certs/app.domain.com_bundle.crt;
   ssl_certificate_key /etc/ssl/server.key;
   location / {
     proxy_pass http://localhost:5000;
   }
}

server {
   listen 443;
   server_name app2.domain.com;
   ssl on;
   ssl_certificate /etc/ssl/certs/app2.domain.com.crt;
   ssl_certificate_key /etc/ssl/server.key;
   location / {
   proxy_pass http://localhost:5002;
   }
}

server {
   listen 443;
   server_name app3.domain.com;
   ssl on;
   ssl_certificate /etc/ssl/certs/app3.domain.com.crt;
   ssl_certificate_key /etc/ssl/server.key;
   location / {
      proxy_pass http://localhost:5001;
   }
}

server {   
   listen 443;
   server_name app4.domain.com;
   ssl on;   
   ssl_certificate /etc/ssl/certs/app4.domain.com_bundle.crt;
   ssl_certificate_key /etc/ssl/server.key;
   location / {
     proxy_pass http://localhost:4999;     
   }
}

And I receive a lot of errors in /var/log/nginx/error.log like the following but not with a specific server or file (in the GET)

2016/10/05 23:59:08 [error] 11439#0: *26933 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 123.123.123.123, server: app4.domain.com, request: "GET /includes/app/language.js HTTP/1.1", upstream: "http://127.0.0.1:4999/includes/app4/language.js", host: "app4.domain.com", referrer: "https://app4.domain.com/"

If I run the same nodejs instance and access it directly, it goes very fast so, I am pretty sure NGINX is the problem.

EDIT: some more details after multiple tests: I am now pretty sure that it is the fact that my app is behind a reverse-proxy that is causing the issue. I reinstalled everything from scratch with only one nodejs app with socket.io. It is running very fast when accessed using http://app.domain.com:5000. Then I tried with nginx and apache2 as reverse proxy to redirect port 80 to 443 and port 443 to the app's port 5000 and it began giving timeouts and becomes very very slow while it stays really fast if accessed directly using port 5000. I guess I am not the only one who wants to have a nodejs server with socket.io running behing a reverse proxy.

Any help would be very welcome. Thanks a lot.

vpx
  • 133
  • 7
  • Please define "very slow" and provide metrics. It doesn;t look slow, it looks like a timeout. More diagnostic information is required. – Tim Oct 06 '16 at 22:51
  • hello @Tim it might indeed be multiple timeouts, but I don't know what metrics to give you. Slow means sometime so slow that it does not show the content after minutes. While accessing the ports directly without ssl, it gives immediate responses – vpx Oct 08 '16 at 11:07
  • @Tim isn't slow defined by *26933 upstream timed out ... meaning it didn't respond no ? – silviud Oct 08 '16 at 19:52
  • I have a similar issue with tornado behind a proxy. Did you find a fix for this? – Alexandru R Oct 21 '16 at 14:25
  • in stead of closing, it would have been nice to tell me which details or info you need to help more... don't you think? – vpx Dec 30 '16 at 11:52

0 Answers0