Apache Virtual Host file ordering

Posted by Itchy-Mycologist939@reddit | linuxadmin | View on Reddit | 9 comments

I have a single virtual host. Does the order of items inside have any significant impact on how its processed. I know my rewrite rules need to go before ErrorDocument, but what about SSL, Logging, CORS, etc...?

My concern is if CORS, SSL and Logging should be placed higher up or if it doesn't matter. Apache doesn't really give much in terms of ordering. https://httpd.apache.org/docs/2.4/vhosts/examples.html

DocumentRoot /var/www/www.example.com

<Directory /var/www/www.example.com>
    ...
    Require all granted
</Directory>

# SSL
SSLEngine On
....

# CORS
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "https://www.example.com"
    ....
</IfModule>

# Rewrite
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_STATUS} =""
    RewriteRule ^/e$ - [R=404,L]
</IfModule>

# Errors
ErrorDocument 403 /e/403.html
ErrorDocument 404 /e/404.html

# Log
LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined