Skip to content

APACHE2 NOTES

Here are some notes regarding how to do various tasks with Apache 2.

SELINUX CONTEXT FOR WEB FILES

chown -R apache:apache /path/to/files
semanage fcontext -a -t httpd_sys_content_t /path/to/files

FORCE SSL/TLS ON HOST

This will force https, and redirect http connections to be https.

    /etc/httpd/conf/httpd.conf

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

PERMANENT DOMAIN REDIRECT

This is to forward a.fqdn.tld to b.fqdn.tld.

Use the Redirect command on the host to forward from.

    /etc/httpd/conf/httpd.conf

    <Directory "/var/www/html">
        #
        #Possible values for the Options directive are "None", "All",
        #or any combination of:
        # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        #Note that "MultiViews" must be named *explicitly* --- "Options All"
        #doesn't give it to you.
        #
        #The Options directive is both complicated and important.  Please see
        #http://httpd.apache.org/docs/2.4/mod/core.html#options
        #for more information.
        #
        Options Indexes FollowSymLinks
        Redirect permanent / https://b.fqdn.tld/

        #
        #AllowOverride controls what directives may be placed in .htaccess files.
        #It can be "All", "None", or any combination of the keywords:
        # Options FileInfo AuthConfig Limit
        #
        AllowOverride None

        #
        #Controls who can get stuff from this server.
        #
        Require all granted
    </Directory>