title: How to use custom location or path instead root for several apps using nginx?
body: <h2>Problem</h2>
  <p>I have a web which works fine on a root domain like <code>mydomain.com</code> without any modification. But if I want to serve it as <code>mydomain.com/app1</code> I I need to modify the source code in the backend and statics links (css, images, etc) in the html</p>
  <ul>
  <li>nodejs :
  <ul>
  <li>from <code>app.get('/')</code>  to <code>app.get('/app1')</code></li>
  </ul>
  </li>
  <li>html
  <ul>
  <li>from <code>src=&quot;main.css&quot;</code> to <code>src=&quot;app1/main.css&quot;</code></li>
  </ul>
  </li>
  </ul>
  <h2>Question</h2>
  <p>Should I always modify the application when I want to assign a <strong>domain/path</strong> using nginx?</p>
  <h2>Sample app</h2>
  <p><a href="https://github.com/jrichardsz/nodejs-static-pages/blob/master/server.js" rel="nofollow noreferrer">https://github.com/jrichardsz/nodejs-static-pages/blob/master/server.js</a></p>
  <pre><code>app.get('/', function(req, res) {
      // ejs render automatically looks in the views folder
      res.render('index');
  });
  </code></pre>
  <h2>Nginx for root domain</h2>
  <p>This is my nginx configuration which works for <strong>mydomain.com</strong></p>
  <pre><code>server {
    listen 80;
    server_name mydomain.com;
   
    location / {
      proxy_pass http://localhost:8080/;
    }
  }
  </code></pre>
  <h2>Attempt for <strong>mydomain.com/app1</strong></h2>
  <pre><code>server {
    listen 80;
    server_name mydomain.com;
    
    location /app1/ { 
      proxy_pass http://localhost:8080/app1/; 
    }
  }
  </code></pre>
  <p>And this is the fix in node js app</p>
  <pre><code>app.get('/app1', function(req, res) {
      // ejs render automatically looks in the views folder
      res.render('index');
  });
  </code></pre>
  <p>I tried :</p>
  <p><a href="https://github.com/expressjs/express-namespace" rel="nofollow noreferrer">https://github.com/expressjs/express-namespace</a></p>
  <p><a href="http://expressjs.com/en/4x/api.html" rel="nofollow noreferrer">http://expressjs.com/en/4x/api.html</a></p>
  <p>But in both cases, I need change my node js app.</p>
  <p>Thanks in advance.</p>