需要使用泛域名解析,

并且加上空的判断,以保证没有二级域名的也可以访问

核心配置

server_name ~^(?<subdomain>.+)\.caipudq\.cn$;
if ( $subdomain = '') {
set $subdomain "tp5caipu";
}
if ( $subdomain = 'www') {
set $subdomain "tp5caipu";
}
root /mnt/www/$subdomain/public;

完整配置

server {
listen 80;
#server_name www.caipudq.cn caipudq.cn ;
#root /mnt/www/tp5caipu/public;
server_name ~^(?<subdomain>.+)\.caipudq\.cn$;
if ( $subdomain = '') {
set $subdomain "tp5caipu";
}
if ( $subdomain = 'www') {
set $subdomain "tp5caipu";
}
root /mnt/www/$subdomain/public;

location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php {
access_log /var/log/nginx/caipudq/access.log; #access_log属于ngx_http_log_module的设置,缺省level为info

error_log /var/log/nginx/caipudq/error.log; #error_log属于core module, 缺省的level是error
index index.php index.html index.htm; #由于是PHP类型的动态页面为主,所以把index.php放在前面效率会更高些

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;
try_files $uri $uri/ /index.php?$args; #普通php网站因为没有rewrite的话,这个不需要
}
location ~ .*\.(jpg|gif|png|bmp)$ {

gzip on;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;

}
error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

}

最新文章

  1. mysql mybatis-generator plugin 分页
  2. softwareTesting_work1
  3. 怎样去除SVN中的某个版本之前的所有版本
  4. el表达式的function标签
  5. Grovvy初识
  6. soa思想,就是远程服务调用
  7. Jackson框架,json转换
  8. Thrift原理与使用实例
  9. 浅谈UML中类之间的五种关系及其在代码中的表现形式
  10. ios开发环境配置及cordova安装与常用命令
  11. centos 7 部署 open-falcon 0.2.0
  12. Slim 文档-First Application 翻译
  13. 利用递归解决“汉诺塔的移动”问题(使用python来做的,其它语言也行)
  14. ThreadLocal类的简单使用
  15. js-完整轮播图
  16. 学习爬虫Scrapy遇到的错误
  17. TZOJ 5225: 玩转二叉树
  18. 使用i5ting_toc 预览 markdown 文件
  19. 2018-2019赛季最后的随想/$\rm{NOIP2018}$游记&#183;启示录
  20. 安全删除U盘或其他硬件 unlocker的使用方法

热门文章

  1. netty传输java bean对象
  2. Linux下Zabbix5.0 LTS监控基础原理及安装部署(图文教程)
  3. 为什么用于开关电源的开关管一般用MOS管而不是三极管
  4. 15个问题自查你真的了解java编译优化吗?
  5. 转:Vivado IP报[Opt 31-67] 错误问题解决方法
  6. Python展示文件下载进度条
  7. SpringBoot之MultipartFile文件上传(6)
  8. node 读取文件内容并响应
  9. sqlalchemy delete object
  10. 如何解决Redis缓存雪崩、缓存穿透