利用nginx泛域名解析配置二級域名和多域名php
網站的目錄結構爲
html
├── bbs
└── wwwhtml
html爲nginx的安裝目錄下默認的存放源代碼的路徑。nginx
bbs爲論壇程序源代碼路徑
www爲主頁程序源代碼路徑服務器
把相應程序放入上面的路徑經過
http://www.youdomain.com 訪問的就是主頁
http://bbs.yourdomain.com 訪問的就是論壇
其它二級域名類推。
dom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
server {
listen 80;
server_name ~^(?<subdomain>.+).yourdomain.com$;
root html/$subdomain;
index index.html index.htm index.php;
fastcgi_intercept_errors on;
error_page 404 = /404.html;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't
# break when using query string
try_files $uri $uri/ =404;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param domain $subdomain;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}
|
總結一下步驟就是網站
1.把上面的紅色配置換成你的域名後添加到你的nginx.conf配置文件spa
2.確認要增長的二級域名,如bbs.yourdomain.comcode
3.設置bbs.yourdomain.com解析到你的nginx服務器ipserver
4.在html目錄下建立bbs目錄htm
5.把源碼放入bbs目錄
6.從新加載nginx配置
kill -HUP cat /usr/local/lnmp/nginx/nginx.conf
(須要把上面命令的路徑換成你的配置文件路徑)
7.訪問http://bbs.yourdomain.com