今天配置awstats,awstats建立出的文件目錄在/home/awstats下,在nginx中加入配置後狂報404,發現仍是忽略了root和alias的區別,特將修改配置記錄以下:
1.失敗:
server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
root /home/awstats/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
}
2.失敗:
server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
alias /home/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
}
3. 成功
server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
alias /home/awstats/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
}
4.成功:
server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
root /home/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
}
從以上例子很明顯看出,仍是對root和alias的概念搞混了~
2. location ~ ^/awstats/ {
alias /home/
3. location ~ ^/awstats/ { #使用alias時目錄名後面必定要加「/」
alias /home/awstats/;
4. location ~ ^/awstats/ {
root /home/;
訪問:
http://test.com/awstats/ 實際訪問的是/home/awstats/ 借用ayou老師的一句話: 通常狀況下,在location /中配置root,在location /other中配置alias是一個好習慣