docker 无法连接到服务器

cx6n0qe3  于 2022-12-03  发布在  Docker
关注(0)|答案(1)|浏览(219)

我正在尝试停靠symfony2应用程序。容器已启动并运行,没有任何错误。但是,当我在浏览器中点击http://localhost:8081时,出现“连接到localhost时发生错误”
docker-compose.yml

version: "3.8"

services:
  app:
    container_name: "${PROJECT_NAME}"
    build:
      context: .
      dockerfile: ./Dockerfile
    restart: 'always'
    ports:
      - 8081:80
    volumes:
      - .:/var/www/html
      - ${LOG_DIR-./logs/apache2}:/var/log/apache2

停靠文件

FROM php:7.0-apache
RUN a2enmod rewrite
COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf
// installing php extensions / libraries and composer .. 
EXPOSE 80
CMD ["apache2-foreground"]

000-default.conf

Listen 80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html/web
    <Directory /var/www/html/web>
        EnableSendfile Off
        AllowOverride None
        Order Allow,Deny
        Allow from All

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app_dev.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>
e3bfsja2

e3bfsja21#

我生成了ssl证书(参考https://medium.com/@nh3500/how-to-create-self-assigned-ssl-for-local-docker-based-lamp-dev-environment-on-macos-sierra-ab606a27ba8a)并更新了文件,如下所示
000-default.conf

// added this to my existing 000-default.conf (pls refer to the question)
<VirtualHost *:443>
    DocumentRoot "/var/www/html/web"
    ServerName localhost
    SSLEngine on
    SSLCertificateFile "/etc/apache2/ssl/server.crt"
    SSLCertificateKeyFile "/etc/apache2/ssl/server.key"
    <Directory /var/www/html/web>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app_dev.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

docker-compose.yml

ports:
      - "8081:80"
      - "8082:443"

停靠文件

FROM php:7.0-apache
COPY server.crt /etc/apache2/ssl/server.crt
COPY server.key /etc/apache2/ssl/server.key
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
COPY php.ini /usr/local/etc/php/php.ini

RUN a2enmod rewrite
RUN a2enmod ssl
// installing php libraries 
// composer install
// EXPOSE ports
CMD ["apache2-foreground"]

相关问题