需求 http://www.xxx.com/company/?id=816 => http://abc.yyy.xxx.com/
程序中可以根据code=abc 查询到id=816
nginx配置如下
server
{
listen 80;
server_name *.yyy.xxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/xxx.com/website;
include none.conf;
location / {
# 重点位置
if ($host ~* ^(.*).yyy.xxx.com) {
set $sub $1;
rewrite ^/ /company/index.php?code=$sub last;
}
try_files $uri $uri/ /index.php?$args;
}
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/xxx.com/access.log;
}
来源:CSDN
作者:zchare
链接:https://blog.csdn.net/zchare/article/details/81135803