Proper virtual host configuration

Hi,

Where is the correct location to put your virtual hosts? A friend told me that it should be like this:
/srv/www/htdocs/web1/index.html
/srv/www/htdocs/web2/index.html

If you read the vhosts.template, it looks like the virtual hosts would be located in the public_html folder in the examples.
/home/username/public_html/web1/index.html
/home/username/public_html/web2/index.html

My impression is that the location should not matter if httpd.conf and the virtual host .conf files are configured correctly.

I could be wrong as I don’t completely understand openSUSE and Apache. I am experiencing a number of problems so I think I should get back to the basics. The openSUSE 11.0 Reference manual is not specific in this matter.

Thanks,
Rob

There is no dictum where they have to be put, but some pattern like /srv/www/vhosts/vhost1/htdocs could be adopted.

Does there need to be an htdocs directory inside of the virtual host directory? I noticed you added that in your example but I understand you are illustrating that the path doesn’t matter.

Hi there. While it would really not seem to matter where you put your virtual hosts, one thing to keep in mind follows.

If you plan on having USERS access your server, to modify web files from within the virtual hosts and check logs etc. It would probably be best to place the virtual hosts static web content in /home/user/public_html and the logs in /home/user/logs and the dynamic content in /home/user/cgi-bin/. This way, users will have access to their content on login, which makes it much more convenient for them, and for you the sysadmin, the layout stays fairly consistent.

If you do not plan on allowing user level access to the virtual hosts directory, placement of the virtual hosts is, within reason, a matter of preference.

Hope this helps, take care!

No, you can call it what you like, I’m just following the pattern of the main host.

As for user access, there is no necessity to locate the files in /home/user because you can change the ownership of the files to the user if they need access and give them a symlink for convenience. More cogent reasons might be which directories get backed up. You may regard virtualhost content as something to include in system backups rather than user directory backup. Another reason might be SELinux considerations (in RH and RH-like systems, and apparently OpenSUSE 11.1, though optional) which require correct context type for files and life is much easier if they are under /srv/www.

As for virtualhost config files, OpenSUSE suggests you use /etc/apache/vhosts.d/*.conf as the place to put config files. It’s quite convenient to put one vhost per file.

As for user access, there is no necessity to locate the files in /home/user because you can change the ownership of the files to the user if they need access and give them a symlink for convenience.

Not to belabor the cognizance of above noted point, but, if you use the users home directory, you can configure /etc/skel to place all relevant web files in any users newly created home directory with the correct perms. Why would one want to add more work for themselves as you point out above with having to create symlinks and set perms for each new user? Sorry, I guess I just don’t see your logic, no offense :wink:

It all comes down to how you regard the user content. Are you giving particular users permission to edit some parts of an organisational website, in which case it is proper that the content should be in system directories. On the other hand, if these are vanity websites for each user, then there is no need to create a virtualhost for each one of them, the userdir module will map

http://www.example.com/~user

to

~user/public_html

And various aspects of the userdir can be configured in /etc/apache2/mod_userdir.conf

So vanity website settings are independent of virtualhost settings.

It all comes down to how you regard the user content. Are you giving particular users permission to edit some parts of an organisational website, in which case it is proper that the content should be in system directories

Well I digress to disagree, but I won’t argue with you just for the sake of arguing, because this is someone elses thread and the whole point I think was well served to help give them some ideas for virtual hosts. Take care!

Well I gave various reasons for preferring /srv/www directories for organisational content like backups and SELinux. It maybe that if the machine is serving mostly user websites, they are better in /home per your scheme. Apache is sufficiently flexible to cater for both situations.

Yes, and it is good information. I guess when I use the word user in the context of virtual hosts I mean it to be synonymous with the word organization or client. Where each new user would be a new organization or client with a virtual host request; if you were hosting web sites. And you are absolutely correct that you can set your virtual hosts up either way, to point somewhere in the filesystem, or to point to a home directory, as apache will let you do so. :smiley: Take care!

Just for the record, Ken’s information did help to solve my issue. It wasn’t really that big of a problem.