网站的目录结构为:
# tree /home/wwwroot/exehack.net
/home/wwwroot/exehack.net
├── bbs
│ └── index.html
└── www
└── index.html
2 directories, 2 files
/home/wwwroot/exehack.net为nginx的安装目录下默认的存放源代码的路径。
bbs为论坛程序源代码路径;www为主页程序源代码路径;把相应程序放入上面的路径通过;http://www.exehack.net 访问的就是主页http://bbs.exehack.net 访问的就是论坛,其它二级域名类推。
有2种方法,推荐方法一
01server {
02listen 80;
03server_name ~^(?<subdomain>.+).exehack.net$;
04access_log /data/wwwlogs/exehack.net_nginx.log combined;
05index index.html index.htm index.php;
06root /home/wwwroot/linuxeye/$subdomain/;
07location ~ .php$ {
08fastcgi_pass unix:/dev/shm/php-cgi.sock;
09fastcgi_index index.php;
10fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
11include fastcgi_params;
12}
13location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
14expires 30d;
15}
16location ~ .*\.(js|css)?$ {
17expires 7d;
18}
19}
方法二、
01server {
02listen 80;
03server_name *.exehack.net;
04access_log /home/wwwlogs/exehack.net_nginx.log combined;
05index index.html index.htm index.php;
06if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
07set $subdomain $1;
08set $domain $2;
09}
10location / {
11root /home/wwwroot/exehack.net/$subdomain/;
12index index.php index.html index.htm;
13}
14location ~ .php$ {
15fastcgi_pass unix:/dev/shm/php-cgi.sock;
16fastcgi_index index.php;
17fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
18include fastcgi_params;
19}
20location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
21expires 30d;
22}
23location ~ .*\.(js|css)?$ {
24expires 7d;
25}
26}
nginx将泛解析的匹配域名绑定到子目录的配置方法如下
复制代码代码如下:
server {
listen 80;
server_name domain.com *.domain.com;
if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
set $subdomain $1;
set $domain $2;
}
location / {
root /home/wwwroot/$domain/$subdomain/;
index index.php index.html index.htm;
#include /home/wwwroot/$domain/$subdomain/.ngx.htaccess;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root /home/wwwroot/$domain/$subdomain/;
fastcgi_pass 127.0.0.1:9100;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。