如何使用虚拟主机在Apache上运行多个项目

如何使用虚拟主机在Apache上运行多个项目

本文介绍了如何使用虚拟主机在Apache上运行多个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的虚拟主机是:

# 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>

我的Windows主机文件具有以下映射

#VIRTUAL DOMAINS

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

我配置的端口是:1983,所以我访问wamp就像:http://localhost:1983/

http://mrs.dev:1983/转到我当前的项目.但是我的其他项目不再可用.

就像我进入dtk.dev:1983/时对每个有效的wamp服务器请求都进入同一个项目http://mrs.dev:1983/一样.

我需要同时在WAMP上运行多个项目.虚拟主机有什么问题?

请帮助

解决方案

您需要使用NameVirtualHost.请参阅Apache手册: http://httpd.apache.org/docs/current/vhosts/name-based.html

赞:

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>

也许这是可行的:

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>

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

解决方案

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>

这篇关于如何使用虚拟主机在Apache上运行多个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:59