【问题标题】:nginx proxy pass express routesnginx 代理传递快速路由
【发布时间】: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


    【解决方案1】:

    Nginx 和 Express 路由必须匹配我

    nginx: 位置/api

    表达: app.get('/api', ...)

    【讨论】:

      猜你喜欢
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 2018-03-04
      • 2011-11-25
      • 2017-08-13
      • 1970-01-01
      相关资源
      最近更新 更多