How do I add virtual hosts the right way while running WHM?

大憨熊 提交于 2019-12-10 17:26:55

问题


I'm running a dedicated server separating accounts for my clients with WHM and CentOS 5. One of my clients has asked me to install subversion, and have the repository stored beneath the webroot.

  • repo's true folder will be in "/home/theirfolder/svn"
  • repo will be accessed through a subdomain on "svn.theirdomain.com"

I know that the regular way to do this is to set up a virtual host in Apache that handles the redirect. The problem is that WHM seems to overtake the whole virtual hosting process, forcing me to bake changes into external files that don't even seem to work for me. When retaining the folder beneath the webroot, I could not get virtual hosting to recognize the path to this folder at all.

The closest I've gotten was instead moving the subversion folder onto the webroot, but even then, my instructions for using Authentication are not followed, so that's not a good solution, security-wise. It also appeared that in this setting pages were being generated by Apache and not by Subversion.

Can anyone here point me in the direction of a tutorial that can guide me through this type of setup, or give me a clear, step-by-step guide on what I need to do? I've tried a lot of things but nothing has really gotten me there. I already have Subversion and all of its dependencies downloaded and installed correctly.

Thanks in advance!


回答1:


One way to accomplish this is to use one of WHM's custom include files, and add your custom <virtualhost> directives there the "regular way". Changes made in these files will survive an automatic rebuild of the Apache configuration files by WHM, while any changes made directly to /etc/httpd/conf/httpd.conf might not.

There are three custom include files that are included by the main httpd.conf at different points. These files (if running Apache 2.x) are located at:

  • /usr/local/apache/conf/includes/pre_virtualhost_2.conf, included before the automatically generated <virtualhost> directives
  • /usr/local/apache/conf/includes/post_virtualhost_2.conf, included after the automatically generated <virtualhost> directives
  • /usr/local/apache/conf/includes/pre_main_2.conf, included at the top of httpd.conf

You can edit these files directly, or via the WHM admin panel (Service Configuration -> Apache Configuration, Include Editor, on WHM 11.30).

I've used post_virtualhost_2.conf to setup additional vhosts for client accounts when WHM/cpanel won't do what I want it to via other configuration methods. Any valid Apache configuration directives can go in the file - it's simply included in its entirety in the main httpd.conf.




回答2:


The instructions above are not what you would use on a per account basis. Anything placed in the apache includes are server wide. You would want to use the apache includes to include the mod dav and mod authz shared object. You probably already have it set but here are instructions just in case. In WHM go to Service Configuration->Apache Configuration->Include Editor Place this in the Pre Main Include:

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

Next you want to make a .conf file and place it in

/usr/local/apache/conf/userdata/std/2/<user account name>/svn.conf

If you want SSL do the same in

/usr/local/apache/conf/userdata/ssl/2/<user account name>/svn.conf

If the directories above are not already present then you will need to create them.

file would contain:

<IfModule mod_dav_svn.c>
<Location /svn>
DAV svn
SVNPath /home/<user account>/svn
AuthType Basic
AuthName "My Repo"
AuthUserFile /etc/svn-auth-conf
Require valid-user
</Location>
</IfModule> 

Username and password can be set with:

htpasswd -cm /etc/svn-auth-conf myusername

Then to commit file changes execute:

/scripts/ensure_vhost_includes --user=<user account>
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd

You should be able to browse to

yourdomain.com/svn 

and it will be pulling from

/home/<user account>/svn


来源:https://stackoverflow.com/questions/6900306/how-do-i-add-virtual-hosts-the-right-way-while-running-whm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!