【问题标题】:Nginx: how to do context path redirect,rewrite or reverse and proxy setting for applicationNginx:如何为应用程序进行上下文路径重定向、重写或反向和代理设置
【发布时间】:2020-10-24 02:25:03
【问题描述】:

我是 NgInx 的新手。 我不知道我必须问或不问,但向前走,我需要它来重定向我的应用程序。 我有 2 个 Asp.net Web 应用程序,并且基于域和上下文路径,我需要重定向到特定应用程序。

app1

env.example.com:9060

app2

env.example.com:9040

例如

第一步:如果我在浏览器中点击这个给定的 url,任何一个应用程序都应该重定向

域名 Url1:abc.example.com

域名 url2: xyz.example.com

Step2 如果我在浏览器中使用上下文路径点击这个给定的 url,那么交叉响应应用程序应该重定向

域 Url1:abc.example.com/app1==>重定向到 app1

域 url2:xyz.example.com/app2==>重定向到 app2

寻找服务器监听和位置指令设置等配置 非常感谢任何帮助。

谢谢。

【问题讨论】:

    标签: nginx nginx-reverse-proxy nginx-location nginx-config


    【解决方案1】:

    据我所知,你想要这样的东西

    default_server 路由所有不匹配的连接see more

    server_name abc.example.com xyz.example.com; 接受任一 URL see more

    location /app1为所需服务器定义特定路由see more

    server {
         listen 80 default_server; # This allows any
         listen [::]:80 default_server; 
    
         listen 443;
         listen [::]:443;
    
         server_name abc.example.com xyz.example.com;
    
         location /app1 { 
             proxy_pass env.example.com:9060;
         }
    
         location /app2 {
             proxy_pass env.example.com:9040;
         }
    }
    

    【讨论】:

    • 目前我有两个域,但未来没有更多域,所以server_name abc.example.com xyz.example.com; 我不想指定
    • 然后删除 server_name 选项,只使用 default_server 这将允许所有域工作
    • 好的,谢谢..在上面面临一个问题,比如在浏览器中点击https://abc.example.com/app1/home/username 和来自网址的app1 自动被删除,它变成了https://abc.example.com/home/username..
    • 不确定您的问题是什么,但如果您希望 URL 相同,您可以执行 location /app1 { proxy_pass env.example.com:9060/app1; }
    猜你喜欢
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 2012-05-12
    • 1970-01-01
    • 2019-03-12
    相关资源
    最近更新 更多