Reputation: 131
I've been configurating WAMP-Server so it will work with several local domains, as following:
http://proloma
http://sweporr
It works good for local use, but I have 2 different .com domains pointing to my server, how could I make it so people over the internet can access different pages by visiting different domains?
My domains is:
www.proloma.com
www.sweporr.com
And they are at the moment both pointing to the same folder (c:/wamp/www).
I want them to point like this:
www.proloma.com -> http://proloma
www.sweporr.com -> http://sweporr
This is my 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 [email protected]
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 [email protected]
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>
This is my hosts:
# 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
And I have followed all these steps: https://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
Upvotes: 1
Views: 1157
Reputation: 131
I fixed it myself!
I just missed the part to put
ServerAlias *.proloma.com proloma.com
ServerAlias *.sweporr.com sweporr.com
Instead of just
ServerAlias www.proloma.com
since the only www case would only target to the right server if I typed www and not if i only typed the url etc.
Upvotes: 0
Reputation: 94682
With Virtual Hosts, Apache basically looks at the incoming url, to decide which Virtual Host to use to server pages from.
It checks the ServerName
and ServerAlias
parameters to find the correct Virtual Host. So all you need to do is change the ServerName
parameter to use the correct .com
tld.
<VirtualHost *:80>
ServerAdmin [email protected]
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 [email protected]
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>
You do not need to change the HOSTS file to get this working for external internet use, as that only effects local accesses.
You will of course have to Port Forward
your router so that external connections on port 80 are not rejected, and are in fact forwarded to the ip address of the PC running Apache.
This PC should of course have a static ip address as well otherwise after a reboot it may be given a different ip address by your routers DHCP server.
Upvotes: 1