我一直在配置WAMP-Server,因此它可以与多个本地域一起使用,如下所示:
http://proloma
http://sweporr
它适合本地使用,但我有2个不同的.com域名指向我的服务器,我怎么能这样做,以便互联网上的人可以通过访问不同的域访问不同的页面?
我的域名是:
www.proloma.com
www.sweporr.com
而且他们现在都指向同一个文件夹(c:/ wamp / www)
我希望他们这样说:
www.proloma.com -> http://proloma
www.sweporr.com -> http://sweporr
这是我的httpd-vhosts.conf:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias www.localhost.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin ranama@proloma.com
DocumentRoot "C:/Users/Proloma/Dropbox/ProlomaDotCom/www"
ServerName proloma
<Directory "C:/Users/Proloma/Dropbox/ProlomaDotCom/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ServerAlias www.proloma.com
ErrorLog "logs/proloma-error.log"
CustomLog "logs/proloma-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin ranama@sweporr.com
DocumentRoot "C:/Users/Proloma/Dropbox/SwePorrDotCom/www"
ServerName sweporr
<Directory "C:/Users/Proloma/Dropbox/SwePorrDotCom/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ServerAlias www.sweporr.com
ErrorLog "logs/sweporr-error.log"
CustomLog "logs/sweporr-access.log" common
</VirtualHost>
这是我的主持人:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 proloma
127.0.0.1 sweporr
我已经遵循了所有这些步骤: https://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
答案 0 :(得分:0)
使用虚拟主机,Apache基本上会查看传入的URL,以决定使用哪个虚拟主机来访问服务器页面。
它会检查ServerName
和ServerAlias
参数以查找正确的虚拟主机。因此,您只需更改ServerName
参数即可使用正确的.com
tld。
<VirtualHost *:80>
ServerAdmin ranama@proloma.com
DocumentRoot "C:/Users/Proloma/Dropbox/ProlomaDotCom/www"
ServerName proloma.com
ServerAlias www.proloma.com
<Directory "C:/Users/Proloma/Dropbox/ProlomaDotCom/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/proloma-error.log"
CustomLog "logs/proloma-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin ranama@sweporr.com
DocumentRoot "C:/Users/Proloma/Dropbox/SwePorrDotCom/www"
ServerName sweporr.com
ServerAlias www.sweporr.com
<Directory "C:/Users/Proloma/Dropbox/SwePorrDotCom/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/sweporr-error.log"
CustomLog "logs/sweporr-access.log" common
</VirtualHost>
您无需更改HOSTS文件即可使其适用于外部互联网,因为这只会影响本地访问。
您当然必须Port Forward
您的路由器,以便端口80上的外部连接不被拒绝,并且实际上转发到运行Apache的PC的IP地址。
这台PC当然应该有一个静态IP地址,否则重启后可能会被你的路由器DHCP服务器给它一个不同的IP地址。
答案 1 :(得分:0)
而不仅仅是 ServerAlias www.proloma.com
因为如果输入www,唯一的www案例只会定位到正确的服务器,而如果我只输入了网址等,则不会定位到正确的服务器。