假设您的 Apache-PHP 容器名为 apache_php。您应该有两个具有相似内容的.conf 文件(或多或少取决于您在 conf 文件中需要什么)。
/etc/apache2/sites-available/minecraft.conf:
<VirtualHost *:80>
ServerName minecraft.com
ServerAdmin webmaster@minecraft
DocumentRoot /home/minecraft
ProxyPreserveHost On
ProxyPass "/" "http://minecraft:25565/"
ProxyPassReverse "/" "http://minecraft:25565/"
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/sites-available/nextcloud.conf:
<VirtualHost *:80>
ServerName nextcloud.com
ServerAdmin webmaster@nextcloud
DocumentRoot /home/nextcloud
ProxyPreserveHost On
ProxyPass "/" "http://nextcloud:8080/"
ProxyPassReverse "/" "http://nextcloud:8080/"
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
注意ProxyPass 和ProxyPassReverse 中的结尾/。如果您不添加它们,最终 URL 将类似于 http://minecraft:25565your_page,而尾随 / 将是 http://minecraft:25565/your_page。
在这种情况下,如果有人进入 minecraft.com,您的 Apache 会将他代理到 minecraft 站点,并且 *minecraft 只能由您的 Apache 容器访问。
请注意,minecraft.com 和 minecraft 是名为 proxy 的网络中的两个不同网站,我将在下面讨论它
这是我在容器中所做的,但让我据我所知解释一下:
假设您的 Apache、Nextcloud 和 Minecraft 位于同一个 network 中(在这种情况下,您应该创建一个网络,在我的情况下它称为 proxy 网络)并且所有这三个容器都应该通过 ping 看到彼此.
你的docker-compose.yml文件在这种情况下应该是什么样子的:
version: '3.9'
services:
apache_php:
build: .
restart: always
ports:
- "81:80"
minecraft:
build: .
restart: always
ports:
- "25565:25565"
nextcloud:
build: .
restart: always
ports:
- "8080:80"
networks:
default:
external:
name: proxy
volumes:
db_data: {}
所以在这个文件中,我创建了三个名为apache_php、minecraft 和nextcloud 的图像,它们是通过Dockerfile 通过build 关键字构建的。我还代理了 81 到 80 端口,25565 到 25565 和 8080 到 80 端口。
然后你可以创建一个Dockerfile或者修改已有的类似内容:
FROM your_os_base:tag
COPY minecraft.conf /etc/apache2/sites-available/
COPY nextcloud.conf /etc/apache2/sites-available/
COPY my_bash_commands.sh /root/
RUN chmod +x /root/my_bash_commands.sh
RUN /root/my_bash_commands.sh
ENTRYPOINT ["your_thing"]
在我的情况下,my_bash_commands.sh 是什么?由于大多数情况下默认 shell 是 sh,因此我创建了一个 bash 文件,以便获得我想要的结果。
my_bash_commands.sh 与此类似:
#!/usr/bash
service apache2 start
a2ensite minecraft
a2ensite nextcloud
a2enmod proxy
a2enmod proxy_http
service apache2 restart
如果你在docker-compose.yml所在的路径中,现在你可以通过运行docker-compose up -d来创建它们,否则你应该使用docker-compose -f /absolute_patht_to/docker-compose.yml up -d。