繁体   English   中英

nginx如何设置子路径代理

[英]How to setup subpath proxy in nginx

我的上游服务器在 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...')
})

我可以很容易地在浏览器中看到两条路线

在此处输入图像描述

在此处输入图像描述

从 ngnix -> Node 设置代理

我尝试了以下配置

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;
}

以上所有配置都在加载http://localhost/但在http://localhost/test上加载 404

try_files提供 static 个文件。 删除此行。

location / {
    proxy_pass http://localhost:3000/;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM