Skip to content

Instantly share code, notes, and snippets.

@zypA13510
Last active August 26, 2024 16:50
Show Gist options
  • Save zypA13510/fc3669a4c6957f3593c6ebed76d1d433 to your computer and use it in GitHub Desktop.
Save zypA13510/fc3669a4c6957f3593c6ebed76d1d433 to your computer and use it in GitHub Desktop.
How to set up a reverse proxy for Recaptcha on Apache httpd
LoadModule ssl_module modules/mod_ssl.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule filter_module modules/mod_filter.so
LoadModule substitute_module modules/mod_substitute.so
<VirtualHost *:443>
ServerName yourdomain.com:443
SSLEngine On
SSLProxyEngine On
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile cert.pem
SSLCertificateKeyFile key.pem
SSLCertificateChainFile chain.pem
ProxyVia On
ProxyRequests Off
ProxyPass "/recaptcha" "https://www.google.com/recaptcha"
ProxyPassReverse "/recaptcha" "https://www.google.com/recaptcha"
AddOutputFilterByType SUBSTITUTE text/html text/css text/javascript application/javascript
Substitute "s/www.google.com/yourdomain.com/ni"
Substitute "s/www.gstatic.com/static.yourdomain.com/ni"
ProxyPassReverseCookieDomain "www.google.com" "yourdomain.com"
ProxyPassReverseCookieDomain "www.gstatic.com" "static.yourdomain.com"
</VirtualHost>
<VirtualHost *:443>
ServerName static.yourdomain.com:443
SSLEngine On
SSLProxyEngine On
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile cert.pem
SSLCertificateKeyFile key.pem
SSLCertificateChainFile chain.pem
ProxyVia On
ProxyRequests Off
ProxyPass "/" "https://www.gstatic.com/"
ProxyPassReverse "/" "https://www.gstatic.com/"
AddOutputFilterByType SUBSTITUTE text/html text/css text/javascript application/javascript
Substitute "s/www.google.com/yourdomain.com/ni"
Substitute "s/www.gstatic.com/static.yourdomain.com/ni"
ProxyPassReverseCookieDomain "www.google.com" "yourdomain.com"
ProxyPassReverseCookieDomain "www.gstatic.com" "static.yourdomain.com"
</VirtualHost>
@Cojad
Copy link

Cojad commented Oct 7, 2023

RequestHeader unset Accept-Encoding
Unset Accept-Encoding is required for Substitute module to work properly to replace strings.

@Cojad
Copy link

Cojad commented Oct 7, 2023

Additionally, since recaptcha load script with intergity check, we need to disable intergrity check with extra substitue like this.
Substitute "s/po.integrity/po.integrit1/ni"
So, broswer will load script without intergrity check.

@M3d-Edge
Copy link

M3d-Edge commented Mar 2, 2024

please where to add this file?

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