【发布时间】:2018-12-26 15:50:40
【问题描述】:
使用以下配置和代码,如果我转到https://domain.co/api/yo
它在 express 应用中寻找“/api/yo”路线,而不仅仅是“/yo”
如何配置 NGINX 以便 express 将 https://domain.co/api/yo 视为“/yo”?
server {
listen 443 default_server;
listen [::]:443 default_server;
root /var/www/domain.co;
index index.html;
server_name domain.co www.domain.co;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain.co/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.co/privkey.pem;
location / {
try_files $uri /index.html;
}
location /api {
proxy_pass http://127.0.0.1:8080;
}
}
app.js
const express = require('express')
const app = express()
app.get('/yo', (req, res) => res.send('Hello World!'))
app.listen(8080, () => console.log('Example app listening on port 8080!'))
【问题讨论】:
标签: express nginx nginx-reverse-proxy