Show Table of Contents
2.6. Configuring the HTTP Server
The HTTP Server is now installed and enabled. The next step is to provide some configuration. The HTTP server already provides some default configuration in
/etc/httpd/conf/httpd.conf, which provides a web host on port 80. We will add some additional configuration to provide an additional web host on a user-specified port.
We use a template file to store our configuration content because the user-defined port requires variable input. In our module, create a directory called
templates and add a file called myserver.conf.erb in the new directory. Add the following contents to the file:
Listen <%= @httpd_port %>
NameVirtualHost *:<%= @httpd_port %>
<VirtualHost *:<%= @httpd_port %>>
DocumentRoot /var/www/myserver/
ServerName <%= @fqdn %>
<Directory "/var/www/myserver/">
Options All Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This template follows the standard syntax for Apache web server configuration. The only difference is the inclusion of Ruby escape characters to inject variables from our module. For example,
httpd_port, which we use to specify the web server port.
Notice also the inclusion of
fqdn, which is a variable that stores the fully qualified domain name of the system. This is known as a system fact. System facts are collected from each system prior to generating each respective system's Puppet catalog. Puppet uses the facter command to gather these system facts and you can also run facter to view a list of these facts.
Edit the
httpd.pp manifest and add the highlighted lines:
class mymodule::httpd {
package { 'httpd':
ensure => installed,
}
service { 'httpd':
ensure => running,
enable => true,
require => Package["httpd"],
}
file {'/etc/httpd/conf.d/myserver.conf':
notify => Service["httpd"],
ensure => file,
require => Package["httpd"],
content => template("mymodule/myserver.conf.erb"),
}
file { "/var/www/myserver":
ensure => "directory",
}
}
This achieves the following:
- We add a file resource declaration for the server configuration file (
/etc/httpd/conf.d/myserver.conf). Thecontentfor this file is themyserver.conf.erbtemplate we created earlier. We also check thehttpdpackage is installed before adding this file. - We also add a second file resource declaration. This one creates a directory (
/var/www/myserverfor our web server. - We also add a relationship between the configuration file and the
httpdservice using thenotify => Service["httpd"]attribute. This checks our configuration file for any changes. If the file has changed, Puppet restarts the service.
We also need to include the
httpd_port parameter in our main manifest file. Edit the init.pp manifest and add the following line:
class mymodule ( $http_port = 80 ) { include mymodule::httpd }
This sets the
httpd_port parameter to a default value of 80. You can override this value with the Satellite Server.
Run the
puppet apply command again to test the changes to our module:
# puppet apply mymodule/tests/init.pp --noop Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults Notice: Compiled catalog for puppet.example.com in environment production in 0.84 seconds Notice: /Stage[main]/Mymodule::Httpd/File[/var/www/myserver]/ensure: current_value absent, should be directory (noop) Notice: /Stage[main]/Mymodule::Httpd/Package[httpd]/ensure: current_value absent, should be present (noop) Notice: /Stage[main]/Mymodule::Httpd/File[/etc/httpd/conf.d/myserver.conf]/ensure: current_value absent, should be file (noop) Notice: /Stage[main]/Mymodule::Httpd/Service[httpd]/ensure: current_value stopped, should be running (noop) Notice: Class[Mymodule::Httpd]: Would have triggered 'refresh' from 4 events Notice: Stage[main]: Would have triggered 'refresh' from 1 events Notice: Finished catalog run in 0.51 seconds
Note
The warning for the
hiera.yaml file is safe to ignore.
The highlighted lines show the creation of the configuration file and our web host directory

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.