I'm pretty new to chef. I'm using it to provision a vagrant development environment using the apache2-windows cookbook, which inconveniently has very little by way of documentation. I have managed to get it to install, and even play nicely with opscodes php cookbook, but I'm struggling to get it to set up a vhost.
So far I have added the vhosts 'extra' to /attributes/default.rb like so:
default['apache']['windows']['extras'] = ["vhosts"]
That successfully adds a 'vhosts.d' directory to apache root, includes httpd-vhosts.conf in httpd.conf, and adds an entry to httpd-vhosts.conf which includes *.conf in the 'vhosts.d' directory.
Unfortunately I can't quite figure out how to use the virtualhost resource provided with the recipe, which looks like it should be putting my vhosts into the 'vhosts.d' using the /templates/default/virtualhost.conf.erb template.
I have added the following to /recipes/default.rb
virtualhost "mysite.localhost" do
server_aliases ["www.mysite.localhost"]
docroot "/vagrant"
action :create
end
but it fails, telling me 'No resource or method named 'virtualhost' for 'Chef::Recipe "default"'.
What am I missing? Is there something else I need to do to allow me to use the virtualhost resource in my recipe?
It's one of the caveat with library cookbooks/LWRP their names are derived from the cookbook name.
Doc is HERE
If apache2-windows is not in the runlist you have to define it with depends 'apache2-windows' in your cookbook metadata.rb.
But the main problem here is that the virtualhost resource will be named apache2_windows_virtualhost due to 2 things:
The resource is derived from the cookbook name, so it become cookbook_resource
Ruby does not allow - in classes names, so they are 'magically' converted to _ for resources calls.
tl;dr; use this
apache2_windows_virtualhost "mysite.localhost" do
server_aliases ["www.mysite.localhost"]
docroot "/vagrant"
action :create
end
Related
I'm trying to deploy a cakephp 3.1 app in a apache 2.4 powered server. My boss would like to place the app in a directory different of server's documentroot (DocumentRoot "/var/www/html" in my httpd.conf file), since multiple webapps will be served by this server.
Instead of virtualhosts, he would like to use aliases (host/app1, host/app2 etc). So I'm trying to configure it this way. I put an alias to my cake app (Alias "/scqa" "/opt/scqa/webroot" in my httpd.conf file) and wrote a RewriteBase (RewriteBase /scqa) to both cake's .htaccess files, but every absolute link present in my app is still pointing to apache's documentroot. In this particular case, it means my css and a big pile of not properly built links are 404ing. Is there some way I can fix it in apache configuration?
I know 2 other ways to fix it: Fix the links with cake syntax (will take me a week) or use virtualhosts. But is it possible to fix it and keep using apache alias?
Thanks in advance.
(The production env uses centos 7 64bits, just in case)
If I understood well, you are using aliases in your .htaccess files.
You should put the Alias in your server config file, because it won't work otherwise.
Syntax: Alias [URL-path] file-path|directory-path
Context: server config, virtual host, directory
From https://httpd.apache.org/docs/current/mod/mod_alias.html
I just to ask a simple question. I am studying the vhost configuration but I am confused where should I properly put my vhosts configuration?
I have a file that has a name httpd-vhosts.conf and httpd.conf
I try to put my configuration in these 2 files but different web projects. And after I restarted my Wampserver I can access them. Is it fine if I place all my vhost entries in the file httpd-vhosts.conf ? Or should I place it in httpd.conf
There is no right or wrong. Apache has one global config file, which typically is the default or specified in the startup script.
This file then uses one or more secondary config files and directories. Different Linux distributions use different default include directories.
On CentOS I think for example you would put a file (named like your domain but can be anything) in /etc/httpd/conf.d/example-com.conf: http://wiki.centos.org/TipsAndTricks/ApacheVhostDir
I recently installed apache2 on ubuntu but I have a problem, my httpd.conf is empty. Can someone give me a clean copy of httpd.conf for apache2 on ubuntu?
Thanks!
Edit: I saw your answers but on wampserver httpd.conf is not empty and as you mentioned it is for user options. SO what should I do?
Edit2 : That's what I got on my apache2.conf, how I add modules, enable gzip and all of that?
[Deleted the contents, as they render the question unreadable and are useless, because that were the default Apache2 configuration under Ubuntu.]
The /etc/apache2/httpd.conf is empty in Ubuntu, because the Apache configuration resides in /etc/apache2/apache2.conf!
“httpd.conf is for user options.” No it isn't, it's there for historic reasons.
Using Apache server, all user options should go into a new *.conf-file inside /etc/apache2/conf.d/. This method should be "update-safe", as httpd.conf or apache2.conf may get overwritten on the next server update.
Inside /etc/apache2/apache2.conf, you will find the following line, which includes those files:
# Include generic snippets of statements
Include conf.d/
As of Apache 2.4+ the user configuration directory is /etc/apache2/conf-available/. Use a2enconf FILENAME_WITHOUT_SUFFIX to enable the new configuration file or manually create a symlink in /etc/apache2/conf-enabled/. Be aware that as of Apache 2.4 the configuration files must have the suffix .conf (e.g. conf-available/my-settings.conf);
It's empty by default. You'll find a bunch of settings in /etc/apache2/apache2.conf.
In there it does this:
# Include all the user configurations:
Include httpd.conf
OK - what you're missing is that its designed to be more industrial and serve many sites, so the config you want is probably:
/etc/apache2/sites-available/default
which on my system is linked to from /etc/apache2/sites-enabled/
if you want to have different sites with different options, copy the file and then change those...
It seems to me, that it is by design that this file is empty.
A similar question has been asked here:
https://stackoverflow.com/questions/2567432/ubuntu-apache-httpd-conf-or-apache2-conf
So, you should have a look for /etc/apache2/apache2.conf
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!
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.
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
Grails tends to write out the URL for everything that uses its tags as /appName/whatever. For instance, if I use the tag:
<g:javascript library="jquery"/>
the resulting tag is
<script src="/appName/jquery/jquery.js"></script>
This causes an issue with using ProxyPass with Apache/Tomcat. All of my CSS, JS, Images and links have that /appName prefixed to them.
Is there a way to work around this with ProxyPass or possibly a way for Grails to not prefix the appName to the front of all of my URL's?
If you don't have another application running as default in your tomcat, or you don't care about replacing it, you must rename you war file to ROOT.war before deploying it. (and delete the directory ROOT if it exists)
If you have severals applications and only one tomcat server, you can use virtualhosts. One virtualhost for each application. (http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html)
If you choose the virtualhosts approach, you must use de virtualhost domain when you define ProxyPass sentences and be sure that the apache server, resolves the virtualhost domain correctly. (if not, you may need to edit he os hosts file)
Sorry about my english.
That works for me, are you trying to run the app as domain.com/ rather than domain.com/appName?
If so, then you'll probably need to specify the base or absolute parameter in the tag.