技术解析

nginx 设定求救
0
2021-05-21 00:06:10
idczone

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


return 301 http://www.$host$request_uri;

$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

谢了、测试过没问题

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服