Nginx泛解析的匹配域名绑定到子目录配置

网站的目录结构为:

 
  1. # tree /home/wwwroot/linuxeye.com
  2. /home/wwwroot/linuxeye.com
  3. ├── bbs
  4. │   └── index.html
  5. └── www
  6.     └── index.html
  7. 2 directories, 2 files

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

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

有2种方法,推荐方法一

方法一:

 
  1. server {
  2. listen 80;
  3. server_name ~^(?<subdomain>.+).linuxeye.com$;
  4. access_log /data/wwwlogs/linuxeye.com_nginx.log combined;
  5. index index.html index.htm index.php;
  6. root /home/wwwroot/linuxeye/$subdomain/;
  7. location ~ .php$ {
  8.     fastcgi_pass unix:/dev/shm/php-cgi.sock;
  9.     fastcgi_index index.php;
  10.     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  11.     include fastcgi_params;
  12.     }
  13. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
  14.     expires 30d;
  15.     }
  16. location ~ .*\.(js|css)?$ {
  17.     expires 7d;
  18.     }
  19. }

方法二:

 
  1. server {
  2. listen 80;
  3. server_name *.linuxeye.com;
  4. access_log /home/wwwlogs/linuxeye.com_nginx.log combined;
  5. index index.html index.htm index.php;
  6. if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
  7.     set $subdomain $1;
  8.     set $domain $2;
  9. }
  10. location / {
  11.     root /home/wwwroot/linuxeye.com/$subdomain/;
  12.     index index.php index.html index.htm;
  13. }
  14. location ~ .php$ {
  15.     fastcgi_pass unix:/dev/shm/php-cgi.sock;
  16.     fastcgi_index index.php;
  17.     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  18.     include fastcgi_params;
  19.     }
  20. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
  21.     expires 30d;
  22.     }
  23. location ~ .*\.(js|css)?$ {
  24.     expires 7d;
  25.     }
  26. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值