我正在使用Docker搭建一个PHP+Apache环境
我创建了 site.conf 并将 VirtualHost 端口号设置为 80,它运行没有任何问题。但是,如果我将 site.conf 中的 VirtualHost 更改为另一个端口(例如 8000),它就不起作用并显示连接被拒绝的错误消息。
工作(VirtualHost *:site.conf 中的 80)
$ docker-compose exec app bash
root@3d0cfdc80ab5:/var/www# curl -l http://localhost:80/phpinfo.php
Displayed the content of the phpinfo() function
没用(VirtualHost *:8000 in site.conf)
$ docker-compose exec app bash
root@3d0cfdc80ab5:/var/www# curl -l http://localhost:8000/phpinfo.php
curl: (7) Failed to connect to localhost port 8000: Connection refused
site.conf
<VirtualHost *:8000> # change 80 to 8000
ServerName localhost:8000 # change 80 to 8000
DocumentRoot /var/www/public_html/cake/
<Directory /var/www/public_html/cake/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Docker文件
FROM php:5.6-apache
RUN echo "\n \
log_errors = On\n error_log = /dev/stderr\n error_reporting = E_NOTICE & E_DEPRECATED\n date.timezone = Asia/Tokyo\n " >> /usr/local/etc/php/php.ini
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends git zip unzip && rm -rf /var/lib/apt/lists
RUN docker-php-ext-install pdo_mysql mysqli
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
ENV PATH="${PATH}:/var/www/cake/lib/Cake/Console"
ENV PATH="${PATH}:/var/www/cake/app/Vendor/bin"
COPY ./site.conf /etc/apache2/sites-available/000-default.conf
COPY . /var/www/
WORKDIR /var/www
RUN mkdir -p tmp/cache/models tmp/cache/persistent && chown -R :www-data tmp && chmod -R 770 tmp
RUN a2enmod rewrite && service apache2 restart
EXPOSE 8000
docker-compose.yml
version: "3"
services:
app:
container_name: app
restart: always
build: .
volumes:
- .:/var/www
ports:
- "8099:8000"
environment:
TZ: "Asia/Tokyo"
depends_on:
- db
db:
image: mysql:5.6
container_name: db
volumes:
- db-data:/var/lib/mysql
ports:
- "33066:3306"
environment:
MYSQL_USER: cake
MYSQL_PASSWORD: cake1234
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: testpass1234
volumes:
db-data:
我是否需要设置除 site.conf、Dockerfile、docker-compose.yml 以外的任何内容来更改 VirtualHost 端口号?
如有任何建议,我们将不胜感激。 谢谢。
各种端口号都试过了,查了资料也没找到解决方法