简体   繁体   English

如何配置 docker-compose.yml 和 nginx conf 文件来读取外部驱动器?

[英]How to configure docker-compose.yml and nginx conf file to read an external drive?

I have nginx in a docker container.我在 docker 容器中有 nginx。 My docker-compose.yml is like this (simplified):docker-compose.yml是这样的(简化版):

nginx:
volumes:
  - /var/www/html:/www/:rw
  - /media/storage:/storage/:rw

Where /var/www/html is my website root and /media/storage is an external drive in my host machine (Azure).其中/var/www/html是我的网站根目录, /media/storage是我的主机 (Azure) 中的外部驱动器。

Now I'm trying to point the website URL example.com/downloads to /storage but without success.现在我试图将网站 URL example.com/downloads指向/storage但没有成功。 My nginx/conf.d/example.com.conf is as following (simplified):我的nginx/conf.d/example.com.conf如下(简化):

server {
listen       80  default;
server_name  example.com;

# this works
root   /www;
index  index.php;
 
# this get a 404 error
location  /downloads{
    root /storage;
}

} }

But I get a 404 error for example.com/downloads .但是我收到example.com/downloads的 404 错误。 What am I forgetting here?我在这里忘记了什么? The file permissions and owner to both paths are the same.两个路径的文件权限和所有者是相同的。 I don't know if the bad configuration is in example.com.conf or in docker-compose.yml .我不知道错误的配置是在example.com.conf还是在docker-compose.yml How should I configure these?我应该如何配置这些?

I solved this myself using alias /storage;我自己使用alias /storage;解决了这个问题alias /storage; instead of root /storage .而不是root /storage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 azure webapp 用于容器 docker-compose.yml 引用 bitnami 图像 - azure webapp for containers docker-compose.yml referencing bitnami images 在composer.yml文件中内联nginx conf:可能吗? - Inline nginx conf in composer.yml file: possible? Azure App Service - 解析docker-compose yml中的环境变量 - Azure App Service - resolving environment variables in docker-compose yml 如何使用 Docker-compose 文件在 Azure WebApp 上部署 Grafana? - How I deploy Grafana on Azure WebApp with Docker-compose file? 在 /etc/nginx/nginx.conf 的上游“php”中找不到 Docker Azure 主机 - Docker Azure host not found in upstream "php" in /etc/nginx/nginx.conf 在 azure 上的 docker compose 文件上指定帐户凭据 - Specify account credentials on a docker compose file on azure Docker 撰写文件上的自定义运行参数 - Docker custom run params on compose file 如何将 Azure 文件共享映射为 Docker Compose 文件中的卷? - How do I map an Azure File Share as a volume in a Docker Compose file? 如何使用 docker-compose 将 Azure 文件共享挂载为容器组的卷? - How to mount Azure File Share as Volume for Container Group using docker-compose? 部署到 Service Fabric 时,如何在 docker-compose 文件中设置有效的 ServiceDnsName? - How do I set a valid ServiceDnsName in my docker-compose file when deploying to Service Fabric?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM