【发布时间】:2015-01-27 23:23:46
【问题描述】:
我有一个具有以下目录结构的网站:
.
├── assets
├── config
├── html
├── spec
└── vendor
我将其用作运行集成测试的开发设置,我需要一个服务器实例。我需要站点根目录位于 html 中,但我需要能够链接到 assets 中的资产。到目前为止,这就是我所拥有的,但它不起作用:
server {
listen 9001;
server_name localhost;
root /Users/hugo/src/feedback/www;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /Users/hugo/src/feedback/www;
index index.html index.htm;
}
location /assets/ {
root /Users/hugo/src/feedback/assets;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# ... all the comments in the default config
}
正在提供页面,但找不到任何资产。它在看这里:
http://localhost:9001/assets/bootstrap/dist/css/bootstrap.min.css
更新
您对目录结构的假设是正确的。 我将配置更改为以下结果相同:
server {
listen 9001;
server_name localhost;
root /Users/hugo/src/feedback/www/html;
index index.html index.htm;
location / {
}
location /assets/ {
# I also tried using 'root' instead of 'alias' but same results
alias /Users/hugo/src/feedback/www/assets;
}
}
【问题讨论】: