2017-08-07 64 views
2

我正在使用最新的Docker for mac。我遇到了这个奇怪的问题。我可以通过http://127.0.0.1/访问我的webapp,但不能使用http://localhost/,但是我可以访问https://localhost/(自签名证书)。所以,我不确定这里有什么问题。本地主机不能在Docker for mac中工作

这是我的码头作曲。

version: "3" 
services: 
    php: 
    build: 
     context: . 
    container_name: php 
    volumes: 
     - .:/var/www/html 
     - conf:/etc/apache2/sites-enabled 
    ports: 
     - "80:80" 
     - "443:443" 

,这是我的Apache配置

<VirtualHost _default_:80> 
    ServerAdmin [email protected] 
    DocumentRoot /var/www/html 

    <Directory /var/www/html> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Require all granted 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 

</VirtualHost> 

<IfModule mod_ssl.c> 
    <VirtualHost _default_:443> 
    DocumentRoot /var/www/html 

    <Directory /var/www/html> 
     Options Indexes FollowSymLinks 
     AllowOverride All 
     Require all granted 
    </Directory> 

    SSLEngine on 
    SSLCertificateFile /etc/apache2/certs/localhost.crt 
    SSLCertificateKeyFile /etc/apache2/certs/localhost.key 

    <FilesMatch "\.(cgi|shtml|phtml|php)$"> 
     SSLOptions +StdEnvVars 
    </FilesMatch> 

    <Directory /usr/lib/cgi-bin> 
     SSLOptions +StdEnvVars 
    </Directory> 

    BrowserMatch "MSIE [2-6]" \ 
     nokeepalive ssl-unclean-shutdown \ 
     downgrade-1.0 force-response-1.0 
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 

    </VirtualHost> 
</IfModule> 
+0

感谢您的链接,但我不是在这里使用XAMPP。同样在我的情况下,https:// localhost(使用https)不能运行http:// localhost(使用http) – nicholasnet

+0

我的猜测是你在Docker容器外部的Mac上的端口80上运行了其他东西。 我会尝试映射端口80到其他东西 - 如8000,然后看看你是否仍然有HTTPS和HTTP问题。 所以,例如: 端口: - '8000:80' 所以,在你的网页浏览器,你将通过 HTTP访问://本地主机:8000 这似乎特别容易,因为你可以访问https,将其映射到端口443. – aldefouw

+0

恐怕情况并非如此。我重复了两次。 – nicholasnet

回答