Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Apache 2.4 and Angular 5+ configuration

Apache 2.4 w/ Angular 5+ configuration

HTTPD Configuration

Virtual host configuration

Example-configuration for Angular 5+ with Apache 2.4. Quite simple configuration, really

     <VirtualHost *:80>
      #-BASIC-CONFIGURATION    
         ServerName where.ever.com
         ServerAdmin you@mail.com
         DocumentRoot "/progs/apache_instance/htdocs"
   
      #-SERVER-CONFIGURATION
         RewriteEngine On
   
      #-DIRECTORY-CONFIGURATION
         <Directory "/progs/apache_instance/htdocs">
            RewriteBase /
            RewriteRule ^index\.html$ - [L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /index.html [L]
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
         </Directory>
   
      #-LOGGING
         CustomLog "|/progs/apache_instance/bin/rotatelogs logs/my-log_log.%Y.%m.%d 86400" common
    </VirtualHost>

CORS to work as intended

In order to allow CORS to work as intended, on the same domain, the following stuff can be added as well:

        SetEnvIf Origin "^(http(s)?://[a-zA-Z\-0-9]+.wherever.com(:?)([0-9]+)?)$" CORS_ALLOW_ORIGIN=$1
        Header always merge Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN
        Header always merge Access-Control-Allow-Credentials true env=CORS_ALLOW_ORIGIN
        Header always set Vary "Origin"

No issues should appear anymore :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment