需要使用泛域名解析,

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

核心配置

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 {
}

}

nginx二级域名指向不同文件项目配置的更多相关文章

  1. nginx 多域名指向多个根目录配置,设置自定义请求头 proxy_set_header,ssl 证书安装配置

    1.nginx.conf 配置文件引入子配置文件 include vhost-server/*.conf;  关键在 server_name  不同域名执行不同的根 user root; #user ...

  2. nginx下配置二级域名指向子目录

    今天终于把nginx的二级域名配置搞定了,哎之前在测试服务器上弄过一次,不过那个是在本地解析的hosts,把ip指向到域名上就ok,再在nginx.conf里改了下配置就好了,用同样的方法改了正式服务 ...

  3. nginx二级域名配置

    CentOs下nginx二级域名配置 域名配置文件 命名规则:XXX.域名信息.conf 配置文件路径:etc/nginx/conf.d/xxxx.conf 配置文件内容:server { liste ...

  4. nginx二级域名配置自动跳转到一级域名

    nginx二级域名配置自动跳转到一级域名 rewrite配置内容: if ($http_host !~ "^www.aaa.com$") { rewrite ^(.*) http: ...

  5. nginx二级域名配置[CentOS]

    目录 背景 域名配置 服务器配置 Nginx配置 页面访问生效 背景 只有一台云服务器,部署了自己写的后端管理系统,又需要部署下自己的个人博客平台,但是只有一个域名,想要合理的利用下二级域名. 域名配 ...

  6. nginx二级域名反向代理

    nginx二级域名反向代理 添加两个开发测试的域名 test.xxx.com :8088 testmobile.xxx.com: 8089 内网地址:127.0.0.1 外网地址:127.0.0.1 ...

  7. Nginx二级域名及多Server反向代理配置

    Nginx强大的正则表达式支持,可以使server_name的配置变得很灵活,如果你要做多用户博客,那么每个用户拥有自己的二级域名也就很容易实现了. 注:nginx反向代理同一ip多个域名,给head ...

  8. centos 安装php-fpm , nginx二级域名配置 ,但为什么必须要 域名提供商 哪里解析新的二级域名一下 才能用呢?

    yum -y install php-fpm php-mysql(当然还有其它扩展) /etc/init.d/php-fpm restart (重启php-fpm) /etc/php.ini (php ...

  9. Nginx多域名多Server反向代理配置

    Nginx强大的正则表达式支持,可以使server_name的配置变得很灵活,如果你要做多用户博客,那么每个用户拥有自己的二级域名也就很容易实现了.下面我就来说说server_name的使用吧:ser ...

随机推荐

  1. Spring Cloud Gateway GatewayFilter的使用

    Spring Cloud Gateway GatewayFilter的使用 一.GatewayFilter的作用 二.Spring Cloud Gateway内置的 GatewayFilter 1.A ...

  2. java中生成和验证jwt

    在这篇文章中主要记录一下在Java中如何使用 java 代码生成jwt token,主要是使用jjwt来生成和验证jwt,关于什么是JWT,以及JWT可以干什么不做详解. jwt的格式: base64 ...

  3. ST表 ----kzsn考挂后有感

    ST表,一个十分神奇的东西,需要O(nlogn)的时间预处理,但是他查询只需要O(1). 看似与线段树等数据结构时间复杂度一样,但是ST表的复杂度只在于预处理,预处理之后可以当做不耗时! 而想线段树这 ...

  4. [BZOJ4399]魔法少女LJJ----------线段树进阶

    感谢线段树进阶,给了我重新做人的机会.---------------某不知名OIer,Keen_z Description 题目描述 在森林中见过会动的树,在沙漠中见过会动的仙人掌过后,魔法少女LJJ ...

  5. gdal注册nsdtfDEM格式驱动配置

    一.关于nsdtf格式 *.dem是一种比较常见的DEM数据格式,其有两种文件组织方式,即NSDTF-DEM和USGS-DEM . NSDTF-DEM NSDTF-DEM是一种明码的中国国家标准空间数 ...

  6. QMake(Qt项目构建)

    qmake工具能够简化不同平台上的项目构建.可以自动产生Makefiles文件,仅仅需要少量的信息就可以生成Makefile文件.同时qmake也可以构建不是Qt的项目.qmake基于项目文件中的信息 ...

  7. 0x04

    二分: while(l<r) { int mid=(l+r)/2; if(符合条件) r=mid; else l=mid+1; } 固定下二分的写法: 终止条件:l==r: 取mid=(l+r) ...

  8. 【前端工具】nodejs+npm+vue 安装(windows)

    预备 先看看这几个是干嘛的,相互的关系是啥. nodejs是语言,类比到php. npm是个包管理,类比到composer. vue是个框架,类比到laravel. webpack是个打包工具. 先下 ...

  9. Kioskcached(2) 之 使用tcmalloc 替换 ptmalloc

    前言 我在 Kioskcached(1)之 Memcached & Redis & Kioskcached 性能测试对比 中找到的一个问题是 malloc,对于一个内存型数据库,很容易 ...

  10. 菜鸡的Java笔记 开发支持类库

    开发支持类库 SupportClassLibrary        观察者设计模式的支持类库                    content (内容)        什么是观察者设计模式呢?   ...