nginx二级域名指向不同文件项目配置
需要使用泛域名解析,
并且加上空的判断,以保证没有二级域名的也可以访问
核心配置
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 {
}
}
最新文章
- mysql mybatis-generator plugin 分页
- softwareTesting_work1
- 怎样去除SVN中的某个版本之前的所有版本
- el表达式的function标签
- Grovvy初识
- soa思想,就是远程服务调用
- Jackson框架,json转换
- Thrift原理与使用实例
- 浅谈UML中类之间的五种关系及其在代码中的表现形式
- ios开发环境配置及cordova安装与常用命令
- centos 7 部署 open-falcon 0.2.0
- Slim 文档-First Application 翻译
- 利用递归解决“汉诺塔的移动”问题(使用python来做的,其它语言也行)
- ThreadLocal类的简单使用
- js-完整轮播图
- 学习爬虫Scrapy遇到的错误
- TZOJ 5225: 玩转二叉树
- 使用i5ting_toc 预览 markdown 文件
- 2018-2019赛季最后的随想/$\rm{NOIP2018}$游记&#183;启示录
- 安全删除U盘或其他硬件 unlocker的使用方法