【问题标题】:Apache vhost not working for subdomainsApache vhost 不适用于子域
【发布时间】:2014-02-22 03:49:42
【问题描述】:

我有这个配置,但 URL app.test.com 和 stage.test.com 重定向到相同的代码/部署

<VirtualHost *:80>
    ServerName app.test.com
    DocumentRoot /var/www/html/Test-Prod/web
    <Directory "/var/www/html/Test-Prod/web">
        Options Indexes FollowSymLinks
        AllowOverride All
    </Directory>
    ErrorLog logs/test-prod__error_log
    CustomLog logs/test-prod_access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerName stage.test.com
    DocumentRoot /var/www/html/Test/web
   <Directory "/var/www/html/Test/web">
        Options Indexes FollowSymLinks
        AllowOverride All
   </Directory>
   ErrorLog logs/test-website_error_log
   CustomLog logs/test-website_access_log common
 </VirtualHost>

【问题讨论】:

    标签: apache vhosts


    【解决方案1】:
    NameVirtualHost *.80
    
    <VirtualHost localhost:80>
        ServerName color
        ServerAlias localhost
        ServerPath "C:/wamp/www/subwww/color"
        DocumentRoot "C:/wamp/www"
        <Directory "C:/wamp/www/subwww/color">
            Options Indexes FollowSymLinks
            AllowOverride All
       </Directory>
    </VirtualHost>
    

    以上代码中,子域名为color

    网址是http://color.localhost/

    如果操作系统是windows,则在“C:/windows/system32/dirvers/etc/hosts”中添加“127.0.0.1 color.localhost”,用记事本作为管理员运行

    【讨论】:

      【解决方案2】:

      如果您仍在使用 httpd 2.2,通常的错误是忽略 NameVirtualHost 指令

      在您的配置文件中添加以下内容,它可能会起作用

      NameVirtualHost *.80
      

      您可能需要阅读Named-based Virtual Host Support with httpd 2.2 的文档。

      【讨论】:

      • 它有效。我刚刚取消了 httpd.conf 文件中 NameVirtualHost *:80 条目的注释
      猜你喜欢
      • 2013-07-13
      • 2015-05-27
      • 2023-03-12
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 2016-04-23
      • 2022-01-07
      • 2017-06-04
      相关资源
      最近更新 更多