【问题标题】:How to setup mass dynamic virtual hosts in nginx on docker?如何在 docker 上的 nginx 中设置海量动态虚拟主机?
【发布时间】:2018-01-09 02:47:48
【问题描述】:

如何在 nginx As seen here 中设置海量动态虚拟主机 除了使用 docker 作为主机?

我目前的设置是这样的:

# default.conf
server {
   root /var/www/html/$http_host;
   server_name $http_host;
 }

在我的 Dockerfile 中

COPY default.conf /etc/nginx/sites-enabled/default.conf 

在我构建映像并运行它之后:

docker run -d 80:80 -v www/:/var/www/html 

但是当我在我的主机文件中指向一个新域 (example.dev) 并创建一个 www/example.dev/index.html 时。它根本不起作用。

【问题讨论】:

  • 您遇到了什么问题? nginx也加载配置吗?你能浏览默认网站吗?
  • @TarunLalwani 是的,它正在加载,但我不认为域被重定向到 docker
  • 检查最新的答案,看看它是否适合你。

标签: docker nginx docker-compose


【解决方案1】:

设置是正确的,它在我的系统上测试时可以正常工作。唯一的问题是您将文件复制到错误的路径上。 docker 镜像默认不使用sites-enabled 路径。默认配置加载 /etc/nginx/conf.d 中的所有内容。因此,您需要复制到该路径并休息一切正常

COPY default.conf /etc/nginx/conf.d/default.conf 

确保正确映射卷。在测试时,我使用下面的 docker 命令对其进行了测试

docker run -p 80:80 -v $PWD/www/:/var/www/html -v $PWD/default.conf:/etc/nginx/conf.d/default.conf nginx

下面是命令行输出

vagrant@vagrant:~/test/www$ mkdir dev.tarunlalwani.com
vagrant@vagrant:~/test/www$ cd dev.tarunlalwani.com/
vagrant@vagrant:~/test/www/dev.tarunlalwani.com$ vim index.html
vagrant@vagrant:~/test/www/dev.tarunlalwani.com$ cat index.html
<h1>This is a test</h1>

浏览器输出

【讨论】:

  • 这不会改变网络根目录。一切仍然指向 html/index.php 而不是 html/example.com/index.php
  • 检查更新的答案,看看你做错了什么
猜你喜欢
  • 2012-01-02
  • 2013-09-08
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 2019-01-10
  • 2015-11-30
相关资源
最近更新 更多