title: Nginx Socket.io SSL giving io is not defined error
body: <p>I am tring to make client server communication using socket.io on a server with https and reverse proxy as nginx.But on client side its giving following errors :</p>
  
  <p>1) GET <a href="https://example.com/socket.io/socket.io.js" rel="nofollow noreferrer">https://example.com/socket.io/socket.io.js</a> 404 not found</p>
  
  <p>2) Reference Error: io is not defined </p>
  
  <p>This is my nginx server block </p>
  
  <pre><code>server {
          listen 80 default_server;
          listen [::]:80 default_server ipv6only=on;
  
  
          root /usr/share/nginx/html;
          index index.html index.htm;
  
          # Make site accessible from http://localhost/
          server_name example.com www.example.com;
  
          location / {
          proxy_pass http://127.0.0.1:8080;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
  
          try_files $uri $uri/ =404;
  
          }
  
          listen 443 ssl;
          ssl_certificate /etc/letsencrypt/live/myreactnative.com/fullchain.pem; 
          ssl_certificate_key /etc/letsencrypt/live/myreactnative.com/privkey.pem; 
          include /etc/letsencrypt/options-ssl-nginx.conf;
          if ($scheme != "https") {
              return 301 https://$host$request_uri;
          } 
  
  }
  </code></pre>
  
  <p>This is my node server file </p>
  
  <pre><code>var express = require('express');
  var app = express();
  var serverPort = 8080;
  var http = require('http');
  var server = http.createServer(app);
  var io = require('socket.io')(server);
  
  app.get('/', function(req, res){
    console.log('get /');
    res.sendFile(__dirname + '/index.html');
  });
  server.listen(serverPort, function(){
  
    console.log('server up and running at %s port', serverPort);
  });
  
  io.on('connection', function(socket){
    console.log('connection');
    socket.on('disconnect', function(){
      console.log('disconnect');
      })
  })
  </code></pre>
  
  <p>my client side is like this :</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;socket client&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  var socket = io();
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the website url <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a></p>
  
  <p>my node application is in directory /usr/share/nginx/html and not in root( but i dont think this can make any difference )</p>