我的目标是部署多个Web应用程序,并通过子域名访问它们。我目前将它们运行在不同的端口上,服务器上有nginx,容器正在运行apache。
我在服务器上运行了nginx,并使用以下服务器设置。
如果有帮助的话,这是我的Dockerfile。
docker run -p 8001:80 -d apache-test1
docker run -p 8002:80 -d apache-test2
我可以通过访问它们来使用它们,只需要去到
http://example.com:8001
但我更喜欢通过子域名来访问它们。
http://example.com:8001 -> http://test1.example.com
http://example.com:8002 -> http://test2.example.com
我在服务器上运行了nginx,并使用以下服务器设置。
server {
server_name test1.anomamedia.com;
location / {
proxy_redirect off;
proxy_set_header Host $host ;
proxy_set_header X-Real-IP $remote_addr ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
proxy_pass http://localhost:8001;
}
}
server {
server_name test2.anomamedia.com;
location / {
proxy_redirect off;
proxy_set_header Host $host ;
proxy_set_header X-Real-IP $remote_addr ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
proxy_pass http://localhost:8002;
}
}
如果有帮助的话,这是我的Dockerfile。
FROM ubuntu
RUN apt-get update
RUN apt-get -y upgrade
RUN sudo apt-get -y install apache2 php5 libapache2-mod-php5
# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container.
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur
# Enable apache mods.
RUN a2enmod php5
RUN a2enmod rewrite
EXPOSE 80
# Copy site into place.
ADD html /var/www/html
# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
# By default, simply start apache.
CMD /usr/sbin/apache2ctl -D FOREGROUND
proxy_pass http://0.0.0.0:8002;
(而不是 localhost)进行配置。 - VonC