0

I have a WordPress site running in a server where now I need to deploy a web app on and since our SSL certificate is not wildcard it has to be under the same domain name too. Now it's running on a different port but users are complaining that is not that friendly to access.

I've setup a reverse proxy because the app is run by another service on the same machine, but when the request is returned to the user it looses the first part of the URL so it ends up on a 404 error.

The WordPress site is running on www.example.com and the web app should be on www.example.com/app but when the request gets back the url looks like www.example.com/Identity... instead of www.example.com/app/Identity...

This is the Virtual Host configuration and the htaccess I'm using in WordPress to allow the /app pass through WordPress routing. I've tried using ProxyPassReverse but it's not working and using mod_rewrite is not an option because the urls from the web app not always start with the same string.

VirtualHost:

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                ServerName www.example.com

                DocumentRoot /var/www/html

                        ProxyPreserveHost On
                        ProxyRequests Off
                        ProxyPass /app http://localhost:5000
                        ProxyPassReverse /app http://localhost:5000/app/

                Header unset X-Frame-Options

                LogLevel trace3

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on

                SSLCertificateFile /etc/apache2/ssl/cert.pem
                SSLCertificateKeyFile /etc/apache2/ssl/private.key
                SSLCertificateChainFile /etc/apache2/ssl/intermediate.pem

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

        </VirtualHost>
</IfModule>

Htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/app.*$ [NC]
RewriteRule . - [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Thanks in advance!

1 Answers1

0
  1. You can remove the entry from the .htaccess files, the file is never read for requests with /app as they are proxied.

  2. You have a misconfiguration there:

    ProxyPass /app http://localhost:5000
    ProxyPassReverse /app http://localhost:5000/app/
    

    Those entries should be identical, both being either localhost:5000/app/ or localhost:5000, depending on the configuration of your appplication. They should also either have a trailing slash on both parameters, or none on both. Mixing this results in URLs that either have a missing slash, or double slashes.

  3. Configure your application to generate the proper URLs. There is usually a setting for this, often called "BaseURL" or something similar. Consult the documentation of your application for this. If for some reason your application doesn't support that, you can configure Apache to rewrite URLs on the fly using the mod_proxy_html directive ProxyHTMLURLMap. This is however a last resort solution, as it requires Apache to rewrite every response before serving it, which adds unnecessary additional load to the server.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89