Nginx服务器php自动进行二级域名泛解析:
目录:想要实现多用户博客系统泛解析二级域名【以baidu.com为例】
例如:用户qulinke1230注册了一个账号,那么他可以通过【qulinke1230.baidu.com】格式访问他的博客
实现:
1、首先要在你的域名里面绑定nginx服务器的ip然后泛解析【*.baidu.com】
2、nginx下的配置
server {listen 80;server_name www.baidu.cn *.baidu.cn;index index.html index.htm index.php;root /alidata/www/baidu/;location ~ .*\.(php|php5)?${#fastcgi_pass unix:/tmp/php-cgi.sock;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires 30d;}location ~ .*\.(js|css)?${expires 1h;}if ( $http_host ~* "^([^\.].*)\.baidu\.cn$") { set $domain $1;rewrite ^(.*) /index.php?member=$domain last; }access_log /alidata/log/nginx/access/baidu.log; }
3、php下实现的小例子
1 <?php 2 3 $type=isset($_GET['member']) ? $_GET['member'] : "default" ; 4 if($type){ 5 echo $type; 6 } 7 8 ?>
4、结果