nginx將泛解析的匹配域名綁定到子目錄配置方法
網(wǎng)站的目錄結(jié)構(gòu)為:
# tree /home/wwwroot/exehack.net
/home/wwwroot/exehack.net
├── bbs
│ └── index.html
└── www
└── index.html
2 directories, 2 files
/home/wwwroot/exehack.net為nginx的安裝目錄下默認(rèn)的存放源代碼的路徑。
bbs為論壇程序源代碼路徑;www為主頁(yè)程序源代碼路徑;把相應(yīng)程序放入上面的路徑通過(guò);http://www.exehack.net 訪問(wèn)的就是主頁(yè)http://bbs.exehack.net 訪問(wèn)的就是論壇,其它二級(jí)域名類推。
有2種方法,推薦方法一
server {
listen 80;
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;
}
}
方法二、
server {
listen 80;
server_name *.exehack.net;
access_log /home/wwwlogs/exehack.net_nginx.log combined;
index index.html index.htm index.php;
if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
set $subdomain $1;
set $domain $2;
}
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將泛解析的匹配域名綁定到子目錄的配置方法如下
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;
}
}
相關(guān)文章
教你快速構(gòu)建一個(gè)基于nginx的web集群項(xiàng)目
本文教你快速構(gòu)建一個(gè)基于nginx的4/7層負(fù)載均衡的web集群項(xiàng)目,項(xiàng)目步驟本文給大家介紹介紹,對(duì)nginx web集群項(xiàng)目感興趣的朋友一起看看吧2021-11-11
Nginx配置多端口多域名訪問(wèn)的實(shí)現(xiàn)
這篇文章主要介紹了Nginx配置多端口多域名訪問(wèn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
使用Nginx實(shí)現(xiàn)根據(jù) IP 匹配指定 URL
最近的一個(gè)項(xiàng)目,需要特定的IP訪問(wèn)某專題頁(yè)面的時(shí)候跳轉(zhuǎn)到網(wǎng)站首頁(yè),思考了下,直接使用NGINX實(shí)現(xiàn),分享給大家。2014-09-09
Nginx Rewrite模塊應(yīng)用的幾種場(chǎng)景
這篇文章主要介紹了Nginx Rewrite模塊應(yīng)用的幾種場(chǎng)景,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

