Httpd.conf setup


















Directives in the configuration files are case-insensitive, but arguments of directives are case sensitive. The ServerName directive is used to set the host name of the server, this is how the server identifies itself. It uses this name when responding to HTTP requests. The location of your configuration files depend on both the Apache version and Linux distribution.

You should always set a ServerName for the server explicitly; it is the only value you need to set to get your server running after installation. By doing this, the server checks its hosts file before consulting with the DNS server. Assuming our domain name is www. If nothing is specified, Apache listens to all addresses and ports on the machine. The default configuration sets the server to listen to port 80, the default port for HTTP communication.

If you only specify an IP address, the server will respond to requests coming to all ports of that address also called an interface. If only a port number is specified, then Apache responds to requests on the specified port arriving at all interfaces on the machine. If your server installation has separate configuration files, you should be able to find or set this directive in the ports.

Alternatively, if you want Apache to listen to ports 80 and on all interfaces regardless of the IP address, you can enter the following:. Doing so makes the server more secure and less vulnerable to attacks. Ideally, the user and group you set should not be able to login to the server ie: have no login credentials and no login shell; they will just be used for handling web client requests. The example above uses anyUserName as our web user and group; just use a name not reserved for other processes.

Next, you need to modify your config file to use the new Apache user and group. If yours says:. Then you need to find where these variables are defined and change their values. Usually, the above directive is preceded by a comment letting you know exactly where to set the new values. Otherwise, you will just insert the new user and group name in place of the old. So your final config lines could look like this:. Any Apache directives using a relative path will, by default, append to the root path specified in ServerRoot.

Press capital G to navigate towards the end of the file. Save and close the file when you are done adding that line. Now that you have your virtual host directories in place, you will create your virtual host file.

Add in the following configuration block, and change the example. This will tell Apache where to find the root directly that holds the publicly accessible web documents.

It also tells Apache where to store error and request logs for this particular site. Now that you have created the virtual host files, you will enable them so that Apache knows to serve them to visitors.

To do this, create a symbolic link for each virtual host in the sites-enabled directory:. Your virtual host is now configured and ready to serve content. SELinux is a Linux kernel security module that brings heightened security for Linux systems.

Since you changed the default configuration by setting up a custom log directory in the virtual hosts configuration file, you will receive an error if you attempt to start the Apache service. To resolve this, you need to update the SELinux policies to allow Apache to write to the necessary files. This step will cover two methods of adjusting Apache policies: universally and on a specific directory. Adjusting policies on directories is more secure, and is therefore the recommended approach.

While this approach is more convenient, it will not give you the same level of control as an approach that focuses on a file or directory policy. The setsebool command changes SELinux Boolean values. The -P flag will update the boot-time value, making this change persist across reboots. Since this option is not universally setting policies, you will need to manually set the context type for any new log directories specified in your virtual host configurations.

This command lists and prints the SELinux context of the directory. You will receive output similar to the following:. This type will allow Apache to generate and append to web application log files:. Next, use the restorecon command to apply these changes and have them persist across reboots:. The -R flag runs this command recursively, meaning it will update any existing files to use the new context. The -v flag will print the context changes the command made. You will receive the following output confirming the changes:.

You can now successfully restart the Apache service:. Now that you have your virtual host set up and SELinux permissions updated, Apache will now serve your domain name. This confirms that your virtual host is successfully configured and serving content. Repeat Steps 4 and 5 to create new virtual hosts with SELinux permissions for additional domains.

Even if you are starting with only a single website, I recommend that you set it up as a virtual host, which will make it easier to add more sites later.

In this article, I'll pick up where we left off in the previous article, so you'll need to set up the original website, a name-based virtual website. Before you set up a second website, you need to get name-based virtual hosting working for the existing site. If you do not have an existing website, go back and create one now. This will be the first virtual host stanza, and it should remain first, to make it the default definition.

That means that HTTP access to the server by IP address, or by another name that resolves to this IP address but that does not have a specific named host configuration stanza, will be directed to this virtual host. All other virtual host configuration stanzas should follow this one.

Last time, we just used the IP address for localhost. Normally, this would be done using whichever name service you use; for example, Google or Godaddy.

Add the entries for both websites so you don't need to edit this file again later. The result looks like this:. It should look like this with some additional text to identify this as website number 1 :. You can then look at the website using the Lynx text mode browser from the command line. You can see that the revised content for the original website is displayed and that there are no obvious errors. Now you are ready to set up the second website. Create a new website directory structure with the following command:.

Create a new configuration stanza in httpd. This stanza tells the web server where to find the HTML files for the second site. Here I have compressed the resulting output to fit this space.



0コメント

  • 1000 / 1000