Skip to content

Instantly share code, notes, and snippets.

@andyshinn
Created September 9, 2016 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andyshinn/3511fbd091dc87ad78771e380fb527d4 to your computer and use it in GitHub Desktop.
Save andyshinn/3511fbd091dc87ad78771e380fb527d4 to your computer and use it in GitHub Desktop.
Mimicking CORS preflight responses in Apache
<VirtualHost _default_:443>
ServerName yourhost
ServerAdmin someperson@yourorg.com
SSLEngine on
SSLCertificateFile /etc/ssl/private/yourorg.com.crt
SSLCertificateKeyFile /etc/ssl/private/yourorg.com.key
SSLCertificateChainFile /etc/ssl/private/chain.pem
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ - [ENV=PREFLIGHT:true]
SetEnvIf Origin "^(.*)$" ORIGIN=$0
Header always set Access-Control-Allow-Origin %{ORIGIN}e env=PREFLIGHT
Header always set Access-Control-Allow-Credentials "true" env=PREFLIGHT
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS" env=PREFLIGHT
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]
ProxyPass / http://host.yourorg.com:8087/
ProxyPassReverse / http://host.yourorg.com:8087/
</VirtualHost>
@dszmaj
Copy link

dszmaj commented Mar 8, 2019

works well on 2.4, thanks for this gist :)

@boussou
Copy link

boussou commented Sep 2, 2019

nice. smart.

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