2017-08-07 58 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

回答