Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Last active January 24, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vegaasen/de1097106bbc6375b7f57b76d261b2b7 to your computer and use it in GitHub Desktop.
Save vegaasen/de1097106bbc6375b7f57b76d261b2b7 to your computer and use it in GitHub Desktop.
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