Host Multiple Domains: Setting Up Virtual Hosts With Webmin
If you want to run multiple websites from your VPS, then you can use Apache's support for Virtual Hosts.
First up, where are you going to put your HTML files? You can put the files anywhere you want, but one useful convention is to have a Linux user per virtual host. And to put the HTML files under that user's home directory. This is especially convenient if the user will be uploading files via FTP, since if you chroot the user's FTP access then they can only access files in their home directory.
To setup a user, run something like this:
username=TheDomainNameWithoutAnyDots
adduser $username
passwd $username
mkdir -p ~$username/htdocs
chown -R $username ~$username
Then, to create a virtual host using Webmin:
•Go to your Webmin control panel.
•Upgrade to the latest version of webmin (required if you are running a version older than 1.080, and normally advisable regardless).
•Go to servers.
•Go to Apache WebServer.
•In the 'Create a New Virtual Server' section select "Any Address" (so you do not end up with a hard coded IP addresses in your conf file)
•Enter 80 for Port (and select the last radio button). This way the VirtualHost will co-exist with any SSL-enabled virtual hosts you add later on. SSL-enabled VirtualHosts need to listen on port 443.
•In the "Document Root" field enter where the virtual host HTML files will be. For example, /home/vhostdomain.com/htdocs.
•For "Server Name" enter the domain name for which you want to serve pages. e.g. "vhostdomain.com"
After you have created the Virtual Host, there are a few other things you may wish to edit.
For example, click on the Virtual Host, and go to Networking and Addresses. Enter an "Alternate virtual server names" of *.YourOtherDomain.com. With this setting, your virtual host will serve pages for http://yourotherdomain.com/ as well as http://www.yourotherdomain.com/.
At this point you may also wish to set other options like "Log Files", so the log files for the Virtual Host end up in separate log file from the main server's log files.
To activate your changes, click "Apply Changes" on the main Apache Webmin page.
Of course, be sure to configure your DNS server so the virtual host domain name points to your server's IP address.
Webmin creates a VirtualHost directive in the Apache config file (/etc/httpd/conf/httpd.conf). An example VirtualHost directive looks like this:
<VirtualHost *:80>
DocumentRoot /home/vhostdomain.com/htdocs
ServerName vhostdomain.com
ServerAlias *.vhostdomain.com
</VirtualHost>
See http://httpd.apache.org/docs/2.2/vhosts/examples.html for some more VirtualHost examples.
Resolving: [warn] _default_ VirtualHost overlapon port 80, the first has precedence
If you get this error when restarting Apache, un-comment the NameVirtualHost *:80 line in /etc/httpd/conf/httpd.conf.
Resolving: 403 Forbidden
Unix needs to be able to 'execute' directories in order to open them (not 'read' them as you would expect). If you get a forbidden error, make sure that the directory containing your HTML files and each of its parent directories has chmod o+x set on it. The following script should do that for you:
dir=/home/somevhostdomain.com/htdocs/;
while true; do
# the exit case when we get to the top level directory /
if [ -z "$dir" -o "$dir" = "/" ]; then
break;
fi;
echo chmodding o+x $dir;
# make the directory exectuable (openable) by others
chmod o+x $dir;
# go 'up' a directory
dir=`dirname $dir`;
done
Redirecting an Incoming Request
Somtimes you have content which has been moved or deleted, but you'd like to return something to the client instead of the dreaded 404 response. In this case, you can use the Redirect directive to specify what you want to do:
# Temporary Redirect (code 302)
Redirect /your/path/file.html http:\//yourdomain.com/some/path/file.html
Redirect temp /your/path/file.html http:\//yourdomain.com/some/path/file.html
# Permanent Redirect (code 301)
Redirect permanent /your/path/file.html http:\//yourdomain.com/some/path/file.html
# Moved (code 303)
Redirect seeother /your/path/file.html http:\//yourdomain.com/some/path/file.html
# Gone (code 410)
Redirect gone /your/path/file.html
Note, these do not have to be static html files; the incoming and redirected requests could be to any resource type.
Karnav Thakar. MCP, MCSA, MCSE, MSITP, CHFI, ECA
Subscribe to:
Post Comments (Atom)
ISM Cyber Security Terms
ISM Cyber Security Terms
-
--> Phase 3 :- Installation of Windows Exchange server standard 2007 SP1 & Move Mailbox, Installtion/Transfer of Commercial Certi...
-
If you have PABX server like Asterisk / Free PBX / Elastix and want to feature to listen / whisper / barge to other calls. ChanSpy can gi...
No comments:
Post a Comment