当前位置: 首页 > news >正文

Nginx泛域名 解析的匹配前缀绑定或转发到子目录

网站的目录结构为:

# tree /home/wwwroot/landui.com

/home/wwwroot/landui.com

├── bbs

│   └── index.html

└── www

    └── index.html

2 directories, 2 files

/home/wwwroot/landui.com为nginx的安装目录下默认的存放源代码的路径。

bbs为论坛程序源代码路径;www为主页程序源代码路径;把相应程序放入上面的路径通过;http://www.landui.com 访问的就是主页http://www.landui.com 访问的就是论坛,其它二级域名类推。

有2种方法,推荐方法一

方法一:

server {

listen 80;

server_name ~^(?<subdomain>.+).landui.com$;

access_log /data/wwwlogs/landui.com_nginx.log combined;

index index.html index.htm index.php;

root /home/wwwroot/landui/$subdomain/;

location ~ .php$ {

    fastcgi_pass unix:/dev/shm/php-cgi.sock;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    include fastcgi_params;

    }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {

    expires 30d;

    }

location ~ .*\.(js|css)?$ {

    expires 7d;

    }

}

方法二:

server {

listen 80;

server_name *.landui.com;

access_log /home/wwwlogs/landui.com_nginx.log combined;

index index.html index.htm index.php;

if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {

    set $subdomain $1;

    set $domain $2;

}

location / {

    root /home/wwwroot/landui.com/$subdomain/;

    index index.php index.html index.htm;

}

location ~ .php$ {

    fastcgi_pass unix:/dev/shm/php-cgi.sock;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    include fastcgi_params;

    }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {

    expires 30d;

    }

location ~ .*\.(js|css)?$ {

    expires 7d;

    }

}

另外: 如果是根据二级名称 分发到不同服务上

若是通配: *.xxxx.com 则需要配置 二级域名的名称获取:

 set $subdomain '';if ($host ~* ^(.*?)\.mydomain.net) {set $subdomain $1;}

然后根据名称 方发到不同的服务:

# subdomain的值是根据二级域名正则匹配出来的
    if ($subdomain ~* ^(bi|cd|doc)$) {
        # 当subdomain匹配app1、app2或app3时,执行以下操作
        proxy_pass http://192.1.4.6:8080;
    }
    if ($subdomain = git) {
        proxy_pass http://192.1.4.7:8080;
    }

http://www.lryc.cn/news/441038.html

相关文章:

  • 黑神话悟空mac可以玩吗
  • Nuxt Kit 中的插件:创建与使用
  • C++(虚构造与虚析构/类型信息运算符/强制类型转换)
  • python毕业设计基于django+vue医院社区医疗挂号预约综合管理系统7918h-pycharm-flask
  • tidb 集群搭建
  • SpringBoot开发——Spring Boot Controller 最佳实践
  • 使用Ubuntu耳机输出正弦波信号
  • Python编程 - 协程
  • 如何在没有备份的情况下恢复 Mac 上丢失的数据
  • SpringBoot:解析excel
  • Tomcat窗口运行修改窗口标题显示项目日期时间
  • 8-----手机机型维修工具助手 功能较全 涵盖解锁 刷机 修复等选项 维修推荐
  • 集群聊天服务器项目【C++】(四)cmake介绍和简单使用
  • Nginx+Tomcat(负载均衡、动静分离)
  • 前端分段式渲染较长文章
  • C#程序员的堕落从nuget开始:将自己的代码发布到nuget
  • 【C/C++语言系列】malloc、calloc和realloc区别和用法
  • 【Linux】POSIX信号量与、基于环形队列实现的生产者消费者模型
  • Spring Boot-消息队列相关问题
  • [数据集][目标检测]岩石种类检测数据集VOC+YOLO格式4766张9类别
  • 图像分割基本知识
  • LIN总线CAPL函数——干扰LIN帧响应段(linInvertRespBit )
  • 【30天玩转python】网络编程基础
  • 【PCB工艺】如何实现PCB板层间的互连
  • FastAPI--如何自定义Docs UI,包括多个APP、静态资源、元数据等
  • 【FPGA XDMA AXI Bridge 模式】PCIe:BARs 和 AXI:BARs 含义解析
  • 嵌入式-QT学习-小练习
  • 使用 Flask-Limiter 和 Nginx 实现接口访问次数限制
  • 【数据结构】排序算法---冒泡排序
  • mysql数据库中事务锁的机制