nginx 设定求救

2017-05-17 17:26:37 +08:00
 zhuccc

我要把 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; 不打算拆开来

2593 次点击
所在节点    NGINX
3 条回复
gqkkk
2017-05-17 17:32:19 +08:00
return 301 http://www.$host$request_uri;
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
2017-05-17 17:41:28 +08:00
@gqkkk 谢了、测试过没问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/362005

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX