how to run multiple projects on Apache using Virtu

2019-06-09 17:30发布

My vhosts are:

# for localhost to work properly
<VirtualHost *:1983>
  ServerAdmin admin@localhost
  DocumentRoot "d:/wamp/www"
  ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)

# afm : Agile Farm Manager
#<VirtualHost *:1983>
#    DocumentRoot "D:/projects/afm/Code"
#    ServerName  dafm.dev
#    <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
#    </Directory>
#</VirtualHost>

# mrs : Meeting Request System
<VirtualHost mrs.dev:1983>
    DocumentRoot "D:/wamp/www/mrs_site/mrs"
    ServerName  mrs.dev
    ServerAlias mrs.dev
    <Directory "D:/wamp/www/mrs_site/mrs">
 Order allow,deny
 Allow from all
 AllowOverride All
    </Directory>
</VirtualHost>

# dtk : Kit Designer
<VirtualHost dtk.dev:1983>
    DocumentRoot "D:/wamp/www/designertoolkit/"
    ServerName  dtk.dev
    ServerAlias dtk.dev
    <Directory "D:/wamp/www/designertoolkit/">
 Order allow,deny
 Allow from all
 AllowOverride All
    </Directory>
</VirtualHost>

And my windows' hosts file has the following mappings

#VIRTUAL DOMAINS

127.0.0.1   dafm.dev
127.0.0.1   mrs.dev
127.0.0.1   dtk.dev

My configured port is :1983 so i access wamp like: http://localhost:1983/

or http://mrs.dev:1983/ goes to my current project. but my other projects are not accessible anymore.

like when i go to dtk.dev:1983/ goes to same project http://mrs.dev:1983/ for every valid request to wamp server.

I need to run multiple projects on WAMP simultaneously. What is the problem with the Virtual Hosts?

please help

2条回答
成全新的幸福
2楼-- · 2019-06-09 17:43

Thanks to the anonymous @user4311956's answer for pointing out that the NameVirtualHost directive is important.

But with my own testing I found out that if I mention NameVirtualHost directive before each Virtual Host i create it works, fails otherwise.

here the code for httpd-vhosts.conf file that worked the magic:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:1983

# for localhost to work properly
<VirtualHost *:1983>
  ServerAdmin admin@localhost
  DocumentRoot "d:/wamp/www"
  ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)

# afm : Agile Farm Manager
#<VirtualHost *:1983>
#    DocumentRoot "D:/projects/afm/Code"
#    ServerName  dafm.dev
#    <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
#    </Directory>
#</VirtualHost>
NameVirtualHost mrs.dev:1983
# mrs : Meeting Request System
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/mrs_site/mrs"
    ServerName  mrs.dev
</VirtualHost>
NameVirtualHost dtk.dev:1983
# dtk : Kit Designer
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/designertoolkit/"
    ServerName  dtk.dev
</VirtualHost>

Thanks again to @user4311956's answer for pointing me in right direction.

查看更多
太酷不给撩
3楼-- · 2019-06-09 17:56

You need to use NameVirtualHost. See Apache manual: http://httpd.apache.org/docs/current/vhosts/name-based.html

Like this:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Maybe this is working:

NameVirtualHost *:1983

# for localhost to work properly
<VirtualHost *:1983>
  ServerAdmin admin@localhost
  DocumentRoot "d:/wamp/www"
  ServerName localhost
</VirtualHost>

# mrs : Meeting Request System
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/mrs_site/mrs"
    ServerName  mrs.dev
    ServerAlias mrs.dev
</VirtualHost>

# dtk : Kit Designer
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/designertoolkit/"
    ServerName  dtk.dev
    ServerAlias dtk.dev
</VirtualHost>

<Directory "D:/wamp/www/designertoolkit/">
    Order allow,deny
    Allow from all
    AllowOverride All
</Directory>

<Directory "D:/wamp/www/mrs_site/mrs">
     Order allow,deny
     Allow from all
     AllowOverride All
</Directory>
查看更多
登录 后发表回答