V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
txwd
V2EX  ›  NGINX

求助, nginx 动态二级域名转换 url 配置

  •  
  •   txwd · 2018-08-07 15:59:43 +08:00 · 3683 次点击
    这是一个创建于 2082 天前的主题,其中的信息可能已经有所发展或是发生改变。

    不知专业名词怎么叫,举个例子吧。 例如我的网站是:www.abc.com 想要的用户访问: user1.abc.com ,实际访问的是 www.abc.com/u?name=user1 user2.abc.com ,实际访问的是 www.abc.com/u?name=user2

    还有,希望用户浏览器的地址显示还是 user1.abc.com ,只是 nginx 做处理。 不知这样的效果有没有解决方案,大家有没有做过类似的。

    类似这样的效果: https://www.jb51.net/article/77364.htm

    5 条回复    2018-08-08 22:27:22 +08:00
    sholmesian
        1
    sholmesian  
       2018-08-07 16:26:31 +08:00 via iPhone
    用定义变量的泛解析,参考: https://holmesian.org/Nginx_resolver


    假设你的后端为 localhost:5555

    server
    {
    listen 80;
    server_name ~^(.*).abc.com$;
    set $key $1;
    location /{
    proxy_pass http://localhost:5555/u?name=$key;
    }
    }
    KuroNekoFan
        2
    KuroNekoFan  
       2018-08-07 16:36:09 +08:00
    proxy_pass
    txwd
        3
    txwd  
    OP
       2018-08-07 16:47:55 +08:00
    @sholmesian 谢谢,我试试。
    txwd
        4
    txwd  
    OP
       2018-08-07 17:31:23 +08:00
    @sholmesian

    server {
    listen 8007;
    server_name www.abc.com;
    #set $key $1;
    location / {
    root C:/nginx/web3;
    index index.html index.htm;
    #proxy_set_header Host $host:8008;
    proxy_pass http://www.baidu.com;
    }
    }
    不行啊,这样写直接跳到百度去了
    sholmesian
        5
    sholmesian  
       2018-08-08 22:27:22 +08:00
    @txwd 增加 proxy_redirect off;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4602 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 65ms · UTC 10:03 · PVG 18:03 · LAX 03:03 · JFK 06:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.