简体   繁体   English

Apache vhost不适用于子域

[英]Apache vhost not working for subdomains

I have this configuration but both url app.test.com & stage.test.com redirect to same code/deployment 我有这个配置,但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>

The usual error for this is leaving out the NameVirtualHost directive if you're still using httpd 2.2 如果您仍在使用httpd 2.2,则通常的错误是NameVirtualHost指令

Add the following in your config file and it'll probably work 在配置文件中添加以下内容,它可能会起作用

NameVirtualHost *.80

You might want to read the documentation for Named-based Virtual Host Support with httpd 2.2 . 您可能希望阅读httpd 2.2的基于命名的虚拟主机支持的文档。

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>

in above code, subdomain name is color 在上面的代码中,子域名是颜色

and the url is http://color.localhost/ 并且网址是http://color.localhost/

if the operating system is windows then add "127.0.0.1 color.localhost" in "C:/windows/system32/dirvers/etc/hosts" with notepad run as administration 如果操作系统是Windows,则在“C:/ windows / system32 / dirvers / etc / hosts”中添加“127.0.0.1 color.localhost”,并以记事本运行为管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM