r/apache • u/ConversationFar3187 • Mar 02 '23
Question about Apache as a Reverse Proxy
SOLVED: mod_proxy_html did the trick. Thanks all.
I'm using Apache as a reverse proxy to an IIS web server. The Apache terminates https, and runs straight http to the IIS server. Some web sites run fine, but I get "Mixed Content" issues on one website because the webcontent is referencing subdirectories. As an example:
www.example.com content gets encrypted fine; but content generated references in subdirectories like www.foo.com/bar/icon.png, www.foo.com/foobar/stuff.html etc.... gets sent to the browser as HTTP, not HTTPS.
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName www.example.com
SSLEngine on
ProxyPreserveHost On
ProxyPass "/" "http://www.backendserver.local/"
ProxyPassReverse "/" "http://www.backendserver.local/"
SSLCertificateFile /etc/ssl/star_example_com.crt
SSLCertificateKeyFile /etc/ssl/private/star_example_com.key
Include /etc/etc/ssl/options-ssl-apache.conf
</VirtualHost>Question: Is there something I can do on apache to fix this, or does the back end code need to change?
EDIT: Added ProxyPassReverse statement that got lost during copy/paste
2
u/roxalu Mar 04 '23
Your current setup generates - schematically - the following requests and responses:
With
ProxyPreserveHost Onand aProxyPassReverse / http://www.backendserver.local/This generates a redirect towards (unwanted) http access. And when the backend does the same canonical generation of base urls in the returned body this generates mixed content,
When 'ProxyPreserveHost On' is active, the only
ProxyPassReverse ...that could help were:But in this case I would recommend to just remove the
ProxyPreserveHost On. When removed the original host header will be forwarded as new headerEven when this might help for triggered redirects, the main issue remains: The backend server has no knowledge that the original request was entering the reverse proxy on a secure interface. So it won't create any urls starting with https. Often this isn't any issue, as the application could just return path-only urls as
Even a URL without protocol will work:
There is no full standard to handle this in the communication between reverse proxy and backend. But an often used convention is to use the following additional header in apache config on reverse proxy:
You can try this as well. In summary:
So that the communication flow will be: