我有nginx安装程序来从/ usr / share / nginx / html服务,并且它做得很好。 我也想添加它从同一个域上的/ home / user / public_html / map服务。 所以:
my.domain.com会让你在/ usr / share / nginx / html中的文件
my.domain.com/map会为你提供/ home / user / public_html / map中的文件
使用下面的configuration(/etc/nginx/nginx.conf),它看起来是去my.domain.com/map/map注意到这一点:
2011/03/12 09:50:26 [error] 2626#0: *254 "/home/user/public_html/map/map/index.html" is forbidden (13: Permission denied), client: <edited ip address>, server: _, request: "GET /map/ HTTP/1.1", host: "<edited>"
我已经尝试了一些东西,但我仍然无法得到它的合作,所以任何帮助将不胜感激。
################################################## #####################
#
#这是主要的Nginxconfiguration文件。
#
################################################## #####################
#------------------------------------------------- ---------------------
#主要模块 - 涵盖基本function的指令
#------------------------------------------------- ---------------------
用户nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
#------------------------------------------------- ---------------------
#活动模块
#------------------------------------------------- ---------------------
事件{
worker_connections 1024;
}
#------------------------------------------------- ---------------------
#HTTP核心模块
#------------------------------------------------- ---------------------
http {
包括/etc/nginx/mime.types;
default_type application / octet-stream;
log_format main'$ remote_addr - $ remote_user [$ time_local]“$ request”'
'$ status $ body_bytes_sent“$ http_referer”'
'“$ http_user_agent”“$ http_x_forwarded_for”';
access_log /var/log/nginx/access.log main;
发送文件;
keepalive_timeout 65;
服务器{
听80;
服务器名称 _;
#access_log logs / host.access.log main;
位置 / {
根/ usr / share / nginx / html;
index index.html index.htm;
}
位置/地图{
root / home / user / public_html / map;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
根/ usr / share / nginx / html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
根/ usr / share / nginx / html;
}
}
包括/etc/nginx/conf.d/*.conf;
}
root指令是这里的问题。 从doc引用:
注意:请记住,根目录仍然会将目录追加到请求中,这样“/i/top.gif”的请求就不会在“/spool/w3/top.gif”中查找,就好像可能发生在Apache-像位置匹配本身的别名configuration被丢弃。 使用别名指令来实现Apache类function。
基本上,只使用root作为真正的根:如果内容是在/使用root。 如果它要在子文件夹上结束,请使用别名:
location /map/ { alias /home/user/public_html/map/; }
还要检查用户nginx运行的是什么,并确保该用户可以访问/home/user/public_html/map