nginx 三级域名泛解析并指向某文件 带参数

需求 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;
}
发布了21 篇原创文章 · 获赞 3 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/zchare/article/details/81135803