Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to setup subpath proxy in nginx

My upstream server running on PORT – 3000

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.get('/test',function(req,res){
  res.send('<h1>Testing...</h1>')
})

app.listen(3000, function () {
  console.log('Listening on port 3000...')
})

I can easily see both routes in the browser

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Setting up the proxy from ngnix -> Node

I tried the following configurations

location ^~ /* {
    try_files $uri $uri/ =404;
    proxy_pass http://localhost:3000/$1;
}

========================================
location / {
    try_files $uri $uri/ =404;
    proxy_pass http://localhost:3000/;
}

========================================
location /* {
    try_files $uri $uri/ =404;
    proxy_pass http://localhost:3000/$1;
}

All the above configuration is loading http://localhost/ but 404 on http://localhost/test

>Solution :

try_filesserves static files. Remove this line.

location / {
    proxy_pass http://localhost:3000/;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading