linux - Nginx 将路由定义为服务器名称

标签 linux nginx server

将 example.com 视为我的基本 URL。我有一个带有路由的独立项目,我希望它仅在我的基本 URL(例如 example.com/a)的一条路由上提供服务。这意味着如果我调用 example.com/a/b,我的分离项目只会收到/b。 我在想这样的事情,但这是错误的:

server {
    listen 80;
    server_name example.com/a;

    location / {
      proxy_pass http://project;
    }
}

最佳答案

对我有用的是使用 rewrite 和 proxy_pass 隐式更改路由而不是 URL,但是此方法仅适用于单个页面,例如,如果您尝试访问 example.com/a/b 此方法有效,但不适用于 example.com/a/b/c:

location /a {
    rewrite a / break;
    # proxy pass to localhost address of separated project
    proxy_pass         http://localhost:3000;
    proxy_redirect     off;
    proxy_set_header   Host $host;
}

关于linux - Nginx 将路由定义为服务器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55136752/

相关文章:

linux - RPM 规范文件未在同一包中执行两个触发器

mysql - 连续从linux中的FIFO管道将数据插入mysql表数据

redirect - nginx 301 重定向与查询字符串

ssl - 使用 Nginx 的 Play Framework 2.3.x 中的 TLS 1.2 实现

javascript - Angular 7 - 生产模式 : I can't navigate through page using the tab key

linux - 找不到 "Qt5Svg"提供的包配置文件

java - 将 Java 应用程序绑定(bind)到接口(interface)

ruby-on-rails - 如何让 nginx 根据 Redis 缓存返回 304 Not Modified?

mysql - 如何最好地跟踪单个数字(例如我的网络应用程序发送的推送数量)?

java - 套接字编程 : Client Disconnection keeps server hanging