Q: Reverse proxy help - URL rewriting
I have OS X server running on Yosemite - standard site setup (http and https) and have been successful in creating a reverse proxy which proxies incoming connections on http://hello.mydomain.com/forum to localhost:8081.
The issue I'm having is that the URLs being sent to the browser from discourse (forums) are formatted like so: https://hello.mydomain.com/assets/something.js rather than https://hello.mydomain.com/forum/assets/something.js
My question surrounds how to implement mod_proxy_html in 0000_127.0.0.1_34580_.conf and 0000_127.0.0.1_34543_.conf
I've enabled the modules httpd.conf. Here are current versions of each which do not work:
0000_127.0.0.1_34580_.conf
<VirtualHost 127.0.0.1:34580>
ServerName default
ServerAdmin admin@example.com
DocumentRoot "/Library/Server/Web/Data/Sites/Default"
DirectoryIndex index.php index.html default.html
CustomLog "/var/log/apache2/access_log" combinedvhost env=!forwarded
CustomLog "/var/log/apache2/access_log" combinedvhostproxy env=forwarded
ErrorLog "/var/log/apache2/error_log"
<IfModule mod_ssl.c>
SSLEngine Off
SSLCipherSuite "ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM"
SSLProtocol -ALL +TLSv1
SSLProxyEngine On
SSLProxyProtocol -ALL +TLSv1
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
</IfModule>
<Directory "/Library/Server/Web/Data/Sites/Default">
Options All -Indexes +ExecCGI -Includes +MultiViews
AllowOverride All
<IfModule mod_dav.c>
DAV Off
</IfModule>
<IfDefine !WEBSERVICE_ON>
Require all denied
ErrorDocument 403 /customerror/websitesoff403.html
</IfDefine>
</Directory>
ServerAlias hello.mydomain.com
<IfModule mod_proxy.c>
<IfModule mod_proxy_http.c>
<IfModule mod_proxy_html.c>
<IfModule mod_headers.c>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /forum http://localhost:8081
ProxyPassReverse /forum http://localhost:8081
<Location “/forum”>
# ask the localhost to return the uncompressed HTML
RequestHeader unset Accept-Encoding
# Filter Responses through mod_proxy_html
SetOutputFilter proxy-html
# convert URLs in CSS and JavaScript as well
ProxyHTMLExtended On
# convert URLs in a.hrefs
ProxyHTMLURLMap ^/ /forum R
# convert URLs in CSS and JS
ProxyHTMLURLMap "'/" “’/forum“
# convert URLs in CSS and JS
ProxyHTMLURLMap "\"/" “\”/forum“
</Location>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !(^localhost|^127.0.0.1|^::1)
RewriteCond %{REQUEST_URI} !^/netboot/ [NC]
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R]
</VirtualHost>
0000_127.0.0.1_34543_.conf
<VirtualHost 127.0.0.1:34543> ServerName default ServerAdmin admin@example.com DocumentRoot "/Library/Server/Web/Data/Sites/Default" DirectoryIndex index.php index.html default.html CustomLog "/var/log/apache2/access_log" combinedvhost env=!forwarded CustomLog "/var/log/apache2/access_log" combinedvhostproxy env=forwarded ErrorLog "/var/log/apache2/error_log" <IfModule mod_ssl.c> SSLEngine Off SSLCipherSuite "ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM" SSLProtocol -ALL +TLSv1 SSLProxyEngine On SSLCertificateFile "/etc/certificates/hello.mydomain.com.23f434fe43f23f23f23fwef3g5g4444ge4gg.cert.pem" SSLCertificateKeyFile "/etc/certificates/hello.mydomain.23f434fe43f23f23f23fwef3g5g4444ge4gg.key.pem" SSLCertificateChainFile "/etc/certificates/hello.mydomain.23f434fe43f23f23f23fwef3g5g4444ge4gg.chain.pem" SSLProxyProtocol -ALL +TLSv1 SSLProxyCheckPeerCN off SSLProxyCheckPeerName off </IfModule> <Directory "/Library/Server/Web/Data/Sites/Default"> Options All -Indexes +ExecCGI -Includes +MultiViews AllowOverride All <IfModule mod_dav.c> DAV Off </IfModule> <IfDefine !WEBSERVICE_ON> Require all denied ErrorDocument 403 /customerror/websitesoff403.html </IfDefine> </Directory> ServerAlias hello.mydomain.com <IfModule mod_proxy.c> <IfModule mod_proxy_http.c> <IfModule mod_proxy_html.c> <IfModule mod_headers.c> ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /forum http://localhost:8081 ProxyPassReverse /forum http://localhost:8081 <Location “/forum”> # ask the localhost to return the uncompressed HTML RequestHeader unset Accept-Encoding # Filter Responses through mod_proxy_html SetOutputFilter proxy-html # convert URLs in CSS and JavaScript as well ProxyHTMLExtended On # convert URLs in a.hrefs ProxyHTMLURLMap ^/ /forum R # convert URLs in CSS and JS ProxyHTMLURLMap "'/" “’/forum“ # convert URLs in CSS and JS ProxyHTMLURLMap "\"/" “\”/forum“ </Location> </IfModule> </IfModule> </IfModule>
</IfModule> </VirtualHost>
Mac OS X Server, OS X Yosemite (10.10.5), null
Posted on May 24, 2016 11:27 AM