Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 13. The Apache HTTP Server
The Apache HTTP Server provides an open-source HTTP server with the current HTTP standards.[14]
In Red Hat Enterprise Linux, the httpd package provides the Apache HTTP Server. Enter the following command to see if the httpd package is installed:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
rpm -q httpd
~]$ rpm -q httpd
package httpd is not installed
If it is not installed and you want to use the Apache HTTP Server, use the
yum utility as the root user to install it:
yum install httpd
~]# yum install httpd
13.1. The Apache HTTP Server and SELinux Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
When SELinux is enabled, the Apache HTTP Server (
httpd) runs confined by default. Confined processes run in their own domains, and are separated from other confined processes. If a confined process is compromised by an attacker, depending on SELinux policy configuration, an attacker's access to resources and the possible damage they can do is limited. The following example demonstrates the httpd processes running in their own domain. This example assumes the httpd, setroubleshoot, setroubleshoot-server and policycoreutils-python packages are installed:
- Run the
getenforcecommand to confirm SELinux is running in enforcing mode:getenforce
~]$ getenforce EnforcingCopy to Clipboard Copied! Toggle word wrap Toggle overflow The command returnsEnforcingwhen SELinux is running in enforcing mode. - Enter the following command as root to start
httpd:systemctl start httpd.service
~]# systemctl start httpd.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Confirm that the service is running. The output should include the information below (only the time stamp will differ):systemctl status httpd.service
~]# systemctl status httpd.service httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: active (running) since Mon 2013-08-05 14:00:55 CEST; 8s agoCopy to Clipboard Copied! Toggle word wrap Toggle overflow - To view the
httpdprocesses, execute the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The SELinux context associated with thehttpdprocesses issystem_u:system_r:httpd_t:s0. The second last part of the context,httpd_t, is the type. A type defines a domain for processes and a type for files. In this case, thehttpdprocesses are running in thehttpd_tdomain.
SELinux policy defines how processes running in confined domains (such as
httpd_t) interact with files, other processes, and the system in general. Files must be labeled correctly to allow httpd access to them. For example, httpd can read files labeled with the httpd_sys_content_t type, but cannot write to them, even if Linux (DAC) permissions allow write access. Booleans must be enabled to allow certain behavior, such as allowing scripts network access, allowing httpd access to NFS and CIFS volumes, and httpd being allowed to execute Common Gateway Interface (CGI) scripts.
When the
/etc/httpd/conf/httpd.conf file is configured so httpd listens on a port other than TCP ports 80, 443, 488, 8008, 8009, or 8443, the semanage port command must be used to add the new port number to SELinux policy configuration. The following example demonstrates configuring httpd to listen on a port that is not already defined in SELinux policy configuration for httpd, and, as a consequence, httpd failing to start. This example also demonstrates how to then configure the SELinux system to allow httpd to successfully listen on a non-standard port that is not already defined in the policy. This example assumes the httpd package is installed. Run each command in the example as the root user:
- Enter the following command to confirm
httpdis not running:systemctl status httpd.service
~]# systemctl status httpd.service httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: inactive (dead)Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the output differs, stop the process:systemctl stop httpd.service
~]# systemctl stop httpd.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Use the
semanageutility to view the ports SELinux allowshttpdto listen on:semanage port -l | grep -w http_port_t
~]# semanage port -l | grep -w http_port_t http_port_t tcp 80, 443, 488, 8008, 8009, 8443Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Edit the
/etc/httpd/conf/httpd.conffile as root. Configure theListenoption so it lists a port that is not configured in SELinux policy configuration forhttpd. In this example,httpdis configured to listen on port 12345:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Enter the following command to start
httpd:systemctl start httpd.service
~]# systemctl start httpd.service Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.Copy to Clipboard Copied! Toggle word wrap Toggle overflow An SELinux denial message similar to the following is logged:setroubleshoot: SELinux is preventing the httpd (httpd_t) from binding to port 12345. For complete SELinux messages. run sealert -l f18bca99-db64-4c16-9719-1db89f0d8c77
setroubleshoot: SELinux is preventing the httpd (httpd_t) from binding to port 12345. For complete SELinux messages. run sealert -l f18bca99-db64-4c16-9719-1db89f0d8c77Copy to Clipboard Copied! Toggle word wrap Toggle overflow - For SELinux to allow
httpdto listen on port 12345, as used in this example, the following command is required:semanage port -a -t http_port_t -p tcp 12345
~]# semanage port -a -t http_port_t -p tcp 12345Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Start
httpdagain and have it listen on the new port:systemctl start httpd.service
~]# systemctl start httpd.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Now that SELinux has been configured to allow
httpdto listen on a non-standard port (TCP 12345 in this example),httpdstarts successfully on this port. - To prove that
httpdis listening and communicating on TCP port 12345, open a telnet connection to the specified port and issue a HTTP GET command, as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
[14]
For more information, see the section named The Apache HTTP Sever in the System Administrator's Guide.