I am assuming you already have Apache 2.2 installed
Step 1: Install Webmin
You can do everything in this blog post manually, but I found webmin extremely useful. It provides a WebGUI for all kinds of services running on your Linux machine, including apache which is what we are going to use it for.
Step 2: Make sure that auth_digest Apache Module is enables
Go to webmin (https://localhost:10000/ if you installed it with the defaults), open the Servers menu on the left hand side, then click on Apache WebServer and then the Global Configuration tab. In there you will find a Configure Apache Modules icon, click on that. In the list of modules that appears, make sure that auth_digest is enabled (tick the box if not). When done click on "Enable Selected Modules"
Step 3: Add a port
I want to use a special port for my Virtual Host so we need to add this to the WebServer config file so it listens to this new port. You can do this in webmin, just go to Servers -> Apache WebServer and click on the Global configuration tab. There you can click on the Networking and Addresses icon. Add your IP address and the port you want your Apache WebServer to listen to the list and hit Save.
Step 4: Create some users
Your Apache Server comes with an application called htdigest (mine was in /usr/bin/htdigest) that you can use to create users. The syntax is:
sudo htdigest -c
e.g.
> sudo htdigest -c /etc/apache/pwds "By Invitation Only" mark
This will prompt you twice for the password of the user. If you want to add another user, use the same command but without the -c, so
> sudo htdigest -c /etc/apache/pwds "By Invitation Only" foobar
The realm is sort of a grouping mechanism, it will be used later.
This should have created a file pwds in /etc/apache and if you open this file you will see the users, their realms and their (encrypted version of) password.
Step 5: Create a Virtual Server
Go back to webmin, Servers -> Apache WebServer and click on the Create virtual host tab. I specified my ip address and the port I specified earlier (step 3), the document root where all the webfiles are that this Virtual Host is pointing to and I also gave a server name (although I am not sure where this is used), I left the rest as default.
Step 6: Create Directives
In order for the users we created to get access to our Virtual Server, we need to change the directive of the virtual server. You can do this in webmin, go to Servers -> Apache WebServer and click on the Existing virtual hosts tab. From the list, select the virtual server you created. From the page that comes up, select Edit Directives and add the following in the
AuthType Digest
AuthName "By Invitation Only"
AuthDigestDomain
# Optional line:
AuthDigestProvider file
AuthUserFile /etc/apache/pwds
Require valid-user
Options +Indexes
You can see we use the realm here in the AuthName label.
And that's it. Go to your website and you will get asked for a user and password or otherwise you cannot get in.
Cheers,
Mark
Virtual Host in Apache
Posted by mvilrokx | 4:02 PM | advanced, apache, how-to, server, tutorial, webserver | 0 comments »
Subscribe to:
Post Comments (Atom)




0 comments
Post a Comment