The minute you think of giving up, think of the reason why you held on so long!
分类: LINUX
2013-12-12 13:59:01
今天配置tomcat项目新增的upload目录,文件目录在/webApp/upload下,在nginx.conf中加入配置后一直404,后来发现忽略了root和alias的区别,特记录:
1.错误配置
server
{
server_name test.com;
index index.html;
location / {
root www;
access_log logs/access.log main;
}
location ^~ /upload/ {
root /webApp/upload/;
index index.html;
access_log off;
error_log off;
}
2.错误配置
server {
server_name test.com;
index index.html;
location / {
root www;
access_log logs/access.log main;
}
location ^~ /upload/ {
alias /webApp/;
index index.html;
access_log off;
error_log off;
}
3.正确配置
server {
server_name test.com;
index index.html;
location / {
root www;
access_log logs/access.log main;
}
location ^~ /upload/ {
alias /webApp/upload/;
index index.html;
access_log off;
error_log off;
}
4.正确配置
server {
server_name test.com;
index index.html;
location / {
root www;
access_log logs/access.log main;
}
location ^~ /upload/ {
root /webApp/;
index index.html;
access_log off;
error_log off;
}
从以上例子很明显看出,还是对root和alias的概念搞混了~
1. location ^~ /upload/ {
root /webApp/upload/;
访问: 实际访问的是/webApp/upload/upload/
2. location ^~ /upload/ {
alias /webApp/
访问: 实际访问的是/webApp/
3. location ^~ /upload/ { #使用alias时目录名后面一定要加“/”
alias /webApp/upload/;
访问: 实际访问的是/webApp/upload/
4. location ^~ /upload/ {
root /webApp/;
访问: 实际访问的是/webApp/upload/
注意:root配置目标目录的上一层,alias配置目标目录
在location
/中配置root,在location /other中配置alias是一个好习惯