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

nginx 设定求救

  •  
  •   zhuccc · 2017-05-17 17:26:37 +08:00 · 2570 次点击
    这是一个创建于 2750 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我要把 aaa.com bbb.com 重定向成 www.aaa.com www.bbb.com,设定如下

    server {
        listen       80;
        server_name  aaa.com bbb.com ccc.com;
    
        return 301 http://www.$server_name$request_uri;
        }
        
    server {
        listen       80;
        server_name  www.aaa.com;
        }
        
    server {
        listen       80;
        server_name  www.bbb.com;
        }
        
    server {
        listen       80;
        server_name  www.ccc.com;
        }
    

    但是不管我打 aaa.com bbb.com ccc.com 返回的网址都是 www.aaa.com 该怎么设定才会打 aaa.com 返回 www.aaa.com,打 bbb.com 返回 www.bbb.com

    因为网址数量不少、所以 server_name aaa.com bbb.com ccc.com; 不打算拆开来

    3 条回复    2017-05-17 17:41:28 +08:00
    gqkkk
        1
    gqkkk  
       2017-05-17 17:32:19 +08:00   ❤️ 1
    return 301 http://www.$host$request_uri;
    gqkkk
        2
    gqkkk  
       2017-05-17 17:33:33 +08:00
    $host
    in this order of precedence: host name from the request line, or host name from the “ Host ” request header field, or the server name matching a request
    $http_name
    arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
    $server_name
    name of the server which accepted a request
    zhuccc
        3
    zhuccc  
    OP
       2017-05-17 17:41:28 +08:00
    @gqkkk 谢了、测试过没问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1136 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:12 · PVG 03:12 · LAX 11:12 · JFK 14:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.