当前位置: 首页 > 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;
    }

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • HarmonyOS鸿蒙开发实战(5.0)自定义全局弹窗实践
  • 汽车总线之---- CAN FD总线
  • nginx upstream转发连接错误情况研究
  • Python | Leetcode Python题解之第429题N叉树的层序遍历
  • Leetcode 每日一题:Diameter of Binary Tree
  • TS React 项目中使用TypeScript
  • 串的存储实现方法(与链表相关)
  • Pybullet 安装过程
  • 面试干货|自动化测试中常见面试题
  • 摆脱困境并在iPhone手机上取回删除照片的所有解决方案
  • 神经网络面试题目
  • Get请求-LocalDateTime的转换问题
  • Python在数据科学与机器学习中的应用
  • 大话Python|基础语法(上)
  • 【监控】【Nginx】使用 Docker 部署 ELK Stack 监控 Nginx
  • bootstrap创建登录注册页面
  • CSS实用技巧
  • Docker入门(二) - Dockerfile
  • express.js的介绍及使用
  • git 常用命令
  • HTTP 简介
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • java8-模拟hadoop
  • Logstash 参考指南(目录)
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • Vue2 SSR 的优化之旅
  • 测试开发系类之接口自动化测试
  • 看完九篇字体系列的文章,你还觉得我是在说字体?
  • 码农张的Bug人生 - 见面之礼
  • 手机端车牌号码键盘的vue组件
  • 小程序滚动组件,左边导航栏与右边内容联动效果实现
  • AI又要和人类“对打”,Deepmind宣布《星战Ⅱ》即将开始 ...
  • mysql面试题分组并合并列
  • #LLM入门|Prompt#1.7_文本拓展_Expanding
  • #微信小程序:微信小程序常见的配置传旨
  • (~_~)
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (function(){})()的分步解析
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (安全基本功)磁盘MBR,分区表,活动分区,引导扇区。。。详解与区别
  • (板子)A* astar算法,AcWing第k短路+八数码 带注释
  • (附源码)spring boot火车票售卖系统 毕业设计 211004
  • (附源码)spring boot网络空间安全实验教学示范中心网站 毕业设计 111454
  • (附源码)springboot车辆管理系统 毕业设计 031034
  • (附源码)springboot课程在线考试系统 毕业设计 655127
  • (附源码)计算机毕业设计ssm基于B_S的汽车售后服务管理系统
  • (十八)用JAVA编写MP3解码器——迷你播放器
  • (四)docker:为mysql和java jar运行环境创建同一网络,容器互联
  • (四十一)大数据实战——spark的yarn模式生产环境部署
  • (太强大了) - Linux 性能监控、测试、优化工具
  • (一)python发送HTTP 请求的两种方式(get和post )
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • ****三次握手和四次挥手
  • .NET Standard 的管理策略
  • .Net 高效开发之不可错过的实用工具