title: Obtain IP address from nodejs using nginx, socket.io and https
body: <p>I'm trying to obtain the client IP address from socket object but since I work in https the address is undefined.</p>
  
  <pre><code>const app = require('https').createServer(optIO).listen(5000);
  const io = require('socket.io').listen(app);
  io.on('connection', function (socket) {
     console.log('connected: ', socket.request.connection.remoteAddress);
  }); 
  </code></pre>
  
  <p>I tried to using headers but I didn't know how to do it.</p>
  
  <p>My default.conf file:</p>
  
  <pre><code>server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      root /var/www/html;
      index index.php index.html;
      server_name  server.com;
      ssl on;
      ssl_certificate /var/www/cer/server.chained.crt;
      ssl_certificate_key /var/www/cer/server.key;
      ssl_prefer_server_ciphers on;
      ssl_protocols TLSv1.2;
      ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
      ssl_session_cache shared:SSL:5m;
      ssl_session_timeout 5m;
      location / {
              try_files $uri $uri/ /index.html;
      }
      add_header Strict-Transport-Security "max-age=15768000" always;
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
            root /var/www/html;
      }
  
      location ~ .php$ {
              try_files $uri =404;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
      }
      location ~ /\.ht {
              deny all;
      } 
  }
  server {
          listen 80;
          listen    [::]:80;
          server_name    server.com;
          return 301 https://www.$server_name$request_uri;
  }
  </code></pre>
  
  <p>My nginx.conf file:</p>
  
  <pre><code>user  nginx;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log warn;
  pid        /var/run/nginx.pid;
  
  
  events {
      worker_connections 4096;
  }
  
  
  http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
  
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
  
      access_log  /var/log/nginx/access.log  main;
  
      sendfile        on;
      #tcp_nopush     on;
  
      keepalive_timeout  5;
  
      gzip  on;
  
      include /etc/nginx/conf.d/*.conf;
  }
  </code></pre>
  
  <p>I'm using Socket.io 2.01, Nginx 1.12.0 and Node.js 6.10 in Debian Jesse.</p>