The directory structure of the Web site is:
# tree/home/wwwroot/exehack.net
/home/wwwroot/exehack.net
├──bbs
│└──index.html
└──www
└──index.html
2 directories, 2 files
/home/wwwroot/exehack.net is the path to the default source code for the Nginx installation directory.
BBS for the Forum program source code path, www for the home Page program source code path, the corresponding program into the above path through; http://www.exehack.net access is the home page http://bbs.exehack.net access is the forum, the other two-level domain name analogy.
There are 2 ways to recommend the method of a
server {
listen;
Server_Name ~^ (? <subdomain>.+). exehack.net$;
Access_log/data/wwwlogs/exehack.net_nginx.log combined;
Index index.html index.htm index.php;
root/home/wwwroot/linuxeye/$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;
}
}
Method Two,
server {
listen;
server_name *.exehack.net;
Access_log/home/wwwlogs/exehack.net_nginx.log combined;
Index index.html index.htm index.php;
if ($host ~* ^ ([^\.] +)\. ([^\.] +\. [^\.] +) $ {
set $subdomain $;
Set $domain $
}
Location/{
root/home/wwwroot/exehack.net/$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;
}
}
Nginx the configuration method that binds a pan-resolved matching domain name to a subdirectory is as follows
Copy Code code as follows:
server {
Listen 80;
server_name domain.com *.domain.com;
if ($host ~* ^ ([^\.] +)\. ([^\.] +\. [^\.] +)$) {
Set $subdomain $;
Set $domain $;
}
Location/{
root/home/wwwroot/$domain/$subdomain/;
Index index.php index.html index.htm;
#include/home/wwwroot/$domain/$subdomain/.ngx.htaccess;
}
Error_page 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;
}
}