Este contenido no está disponible en el idioma seleccionado.
2.4. Configuration examples
The following examples provide real-world demonstrations of how SELinux complements the Apache HTTP Server and how full function of the Apache HTTP Server can be maintained.
2.4.1. Running a static site Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
To create a static website, label the
.html files for that website with the httpd_sys_content_t type. By default, the Apache HTTP Server cannot write to files that are labeled with the httpd_sys_content_t type. The following example creates a new directory to store files for a read-only website:
- Run the
mkdir /mywebsitecommand as the root user to create a top-level directory. - As the root user, create a
/mywebsite/index.htmlfile. Copy and paste the following content into/mywebsite/index.html:<html> <h2>index.html from /mywebsite/</h2> </html>
<html> <h2>index.html from /mywebsite/</h2> </html>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - To allow the Apache HTTP Server read only access to
/mywebsite/, as well as files and subdirectories under it, label/mywebsite/with thehttpd_sys_content_ttype. Run the following command as the root user to add the label change to file-context configuration:semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"
~]# semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run the
restorecon -R -v /mywebsitecommand as the root user to make the label changes:restorecon -R -v /mywebsite
~]# restorecon -R -v /mywebsite restorecon reset /mywebsite context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /mywebsite/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0Copy to Clipboard Copied! Toggle word wrap Toggle overflow - For this example, edit
/etc/httpd/conf/httpd.confas the root user. Comment out the existingDocumentRootoption. Add aDocumentRoot "/mywebsite"option. After editing, these options should look as follows:#DocumentRoot "/var/www/html" DocumentRoot "/mywebsite"
#DocumentRoot "/var/www/html" DocumentRoot "/mywebsite"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run the
service httpd statuscommand as the root user to see the status of the Apache HTTP Server. If the server is stopped, run theservice httpd startcommand as the root user to start it. If the server is running, run theservice httpd restartcommand as the root user to restart the service (this also applies any changes made tohttpd.conf). - Use a web browser to navigate to
http://localhost/index.html. The following is displayed:index.html from /mywebsite/
index.html from /mywebsite/Copy to Clipboard Copied! Toggle word wrap Toggle overflow