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

柔情痞子 提交于 2019-12-02 02:59:09

需求 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;
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!