title: Why am I getting 404 error on this URL https://davedevzone.com/chat/ and not directly from port https://davedevzone.com:3001
body: <p>Hi I'm having trouble setting up the path of a nodejs app but I'm not sure if it has to do with the way I configured nginx or the way I'm setting up my application.</p>
  
  <p>Basically I want to serve the following: <a href="https://davedevzone.com:3001/" rel="nofollow noreferrer">https://davedevzone.com:3001/</a></p>
  
  <p>as a nice formated url without the port, like this: <a href="https://davedevzone.com/chat/" rel="nofollow noreferrer">https://davedevzone.com/chat/</a></p>
  
  <p>However, when I try to go to that last url, as you can see it crashes with 404 errors on every resource it tries to load (css files and js files)</p>
  
  <p>I've noticed that if I replace the local path for each resource tag with the full url including the port it solves the issue. For example: </p>
  
  <p><a href="https://davedevzone.com:3001/css/site.css" rel="nofollow noreferrer">https://davedevzone.com:3001/css/site.css</a></p>
  
  <p>loads fine. But I'm not sure if this is the proper way to things or if it will bring me any complications in the future. For me it feels like the easy way out and that's usually never good in my experience.</p>
  
  <p>Here's the full code of my app:</p>
  
  <p><strong>index.js (server side)</strong></p>
  
  <pre><code>var port = 3001; // app's port
  var fs = require('fs');
  var https = require('https');
  var express = require('express');
  var app = express();
  //var http = require('http').Server(app);
  var server = https.createServer({
      key: fs.readFileSync('privkey.pem'),
      cert: fs.readFileSync('fullchain.pem')
  },app);
  
  var io = require('socket.io')(server);
  
  
  app.use('/css', express.static('css'));
  app.use('/js', express.static('js'));
  
  app.get('/', function(req, res){
      res.sendFile(__dirname + '/index.html');
  });
  
  io.on('connection', function(socket){
      console.log('a user connected');
      socket.on('disconnect', function(){
          console.log('user disconnected');
      });
      socket.on('chat message', function(msg){
          console.log('message: ' + msg);
          socket.broadcast.emit('chat message', msg);
      });
  });
  
  
  server.listen(port, function(){
      console.log('listening on *:' + port);
  });
  </code></pre>
  
  <p><strong>index.html (client)</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Socket.IO chat&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="/css/site.css" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;ul id="messages"&gt;&lt;/ul&gt;
      &lt;form action=""&gt;
        &lt;input id="m" autocomplete="off" /&gt;&lt;button&gt;Send&lt;/button&gt;
      &lt;/form&gt;
      &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;script src="/js/jquery-1.11.1.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          var socket = io();
  
          $('form').submit(function(e){
              e.preventDefault();
              var msg = $('#m').val();
              socket.emit('chat message', msg);
              $('#messages').append($('&lt;li&gt;').text(msg));
              $('#m').val('');
              return false;
          });
  
          socket.on('chat message', function(msg){
              $('#messages').append($('&lt;li&gt;').text(msg));
          });
  
          console.log("from nodeprojects folder");
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>my <strong>nginx config file</strong> from /etc/nginx/sites-available/davedevzone.com</p>
  
  <pre><code>server {
      listen 80;
  
      index index.html index.html index.nginx-debian.html;
  
      server_name davedevzone.com www.davedevzone.com;
  
      location /sample/ {
          proxy_pass http://127.0.0.1:3000/;
      }
  
      location /chat/ {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;
  
          proxy_pass https://127.0.0.1:3001/;
          proxy_redirect off;
  
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
      } 
  
  
      listen [::]:443 ssl ipv6only=on; # managed by Certbot
      listen 443 ssl; # managed by Certbot
      ssl_certificate /etc/letsencrypt/live/davedevzone.com/fullchain.pem; # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/davedevzone.com/privkey.pem; # managed by Certbot
      include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
      ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  
  
  }
  </code></pre>