title: nodejs http.createServer read url and remove urlprefix
body: <p>Here is what i want:</p>
  
  <blockquote>
    <p>I have an url "10.0.0.1/0000000/abctest/filedirectory/filename", </p>
    
    <p>and with this url, I can read the file accordingly</p>
  </blockquote>
  
  <p>Thus, i create a server with "http.createServer" and binded at 8001 port, and set nginx that whenever it read /0000000/abctest/, it will redirect to port 8001</p>
  
  <p>After i added the nginx reverse proxy, I try to write my server code, and here is my http server code</p>
  
  <pre><code>var port = 8001;
  var http = require('http');
  var fs = require('fs');
  
  var DefaultFileDir = '/home/ubuntu/Server/Proj/static'; 
  var UrlPrefix = "/0000000/abctest"
  var hostname = "127.0.0.1"
  
  //var host = hostname+UrlPrefix
  var server= http.createServer(function(req,res){
      var url = req.url; 
      console.log(url);
      var file = DefaultFileDir + url;
  
      fs.readFile(file, function(err,data){
          if(err){
              console.log(err);
              res.writeHeader(404,{
                  'content-type' : 'text/html;charset="utf-8"'
              });
              res.write('&lt;h1&gt;404&lt;/h1&gt;');
              res.end();
          }else{
              if(url.substr(url.length-3, 3) == ".gz"){
                  res.writeHeader(200,{
                      'Content-Encoding' : 'gzip',
                      'content-type' : 'application/octet-stream'
                  });
              }else{
                  res.writeHeader(200,{
                      'content-type' : 'text/html;charset="utf-8"'
                  });
              }
              res.write(data);
              res.end();
          }
      });
  
  }).listen(port,hostname);
  console.log("Static file server running at\n  =&gt; http://localhost:" + port + "/\nCTRL + C to shutdown");
  </code></pre>
  
  <p>And the problem come out:
  it dont know how to ignore the url prefix "/0000000/abctest" </p>
  
  <pre><code>Error: ENOENT: no such file or directory, open '/home/ubuntu/xxxxx/static/0000000/abctest/folder001/index.html'
  </code></pre>
  
  <p>However my actual file path shall be '/home/ubuntu/xxxxx/static/folder001/index.html'</p>
  
  <p>is that http.createserver cannot ignore the url prefix? May i seek for some hints from that.</p>