nginx 三級域名泛解析並指向某檔案 帶引數
阿新 • • 發佈:2019-01-02
需求 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; }