【发布时间】:2017-09-01 16:07:28
【问题描述】:
Nginx 将根目录中的所有静态内容服务到根 URL。例如,如果根内容位置配置为 /usr/share/nginx/html,其中包含一个文件 /usr/share/nginx/html/foo.html,则 url http://localhost/foo.html 将提供该 html 文件。我想在 URL 中添加一个上下文路径前缀,以便 http://localhost/myapp/foo.html 应该服务于 /usr/share/nginx/html/foo.html 文件。
我尝试更改位置并添加别名,但结果为 404。
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /myapp/ {
alias /usr/share/nginx/html/;
}
我还希望http://localhost/myapp 应该服务于/usr/share/nginx/html/index.html
我正在使用 nginx 的 1.12.1-alpine docker 镜像
【问题讨论】:
标签: nginx nginx-location