0

EDIT - Added Vhosts config for the target subdomain.

I am trying to reverse proxy blog.subdomain.com to tld.com/blog. The current config I have right now redirects to the subdomain rather than render the data in the TLD itself.

I am using apache2 on both the servers, using AWS's Lightsail instance for both.

<VirtualHost _default_:443>
  ServerAlias *
  SSLEngine on
  SSLCertificateFile "/opt/bitnami/apache/conf/example.com.crt"
  SSLCertificateKeyFile "/opt/bitnami/apache/conf/example.com.key"
  DocumentRoot "/home/bitnami/htdocs/example-landing/public"

  # BEGIN: Configuration for letsencrypt
  Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
  # END: Configuration for letsencrypt

  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    # ProxyPass /.well-known !
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

    ProxyPass /blog http://blog.example.com
    ProxyPassReverse /blog http://blog.example.com
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location

  <Directory "/home/bitnami/htdocs/example-landing/public">
    Require all granted
  </Directory>
  # This is for the Nodejs application running on the server
  ProxyPass / http://localhost:3000/
  ProxyPassReverse / http://localhost:3000/
  
  # This is for the actual blog
  ProxyPass /blog
  ProxyPassReverse /blog http://blog.example.com

  # BEGIN: Support domain renewal when using mod_proxy within Location
  <Location /.well-known>
    <IfModule mod_proxy.c>
     ProxyPass !
    </IfModule>
  </Location>

  # END: Support domain renewal when using mod_proxy within Location
</VirtualHost>

Configuration for the blog.example.com

httpd-vhosts.conf

<VirtualHost *:80>
    ServerName ghost.example.com
    ServerAlias www.ghost.example.com
    DocumentRoot "/opt/bitnami/apps/ghost/htdocs"

Include "/opt/bitnami/apps/ghost/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
    ServerName ghost.example.com
    ServerAlias www.ghost.example.com
    DocumentRoot "/opt/bitnami/apps/ghost/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apps/ghost/conf/certs/server.crt"
    SSLCertificateKeyFile "/opt/bitnami/apps/ghost/conf/certs/server.key"

Include "/opt/bitnami/apps/ghost/conf/httpd-app.conf"
</VirtualHost>

httpd-app.conf

Include "/opt/bitnami/apps/ghost/conf/banner.conf"

ProxyPass /bitnami !
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/
Sahil
  • 133
  • 6

1 Answers1

0

Two things:

ProxyPass rules are processed in the order they are listed in your configuration, the first match wins.

In the order below a request for www.example.com/blog/page.html is matched by the first ProxyPass directive and will never reach the second ProxyPass directive:

ProxyPass / http://localhost:3000
ProxyPass /blog http://blog.example.com

Switch the order around:

ProxyPass /blog http://blog.example.com
ProxyPass / http://localhost:3000

and www.example.com/blog/page.html will match the first directive and get forwarded to your blog and a request for www.example.com/images/logo.png will not match the first ProxyPass directive and will fall through and get processed by the second directive.

Once you have changed that and your blog still won't show properly under www.example.com/blog and continues to redirect to the subdomain: there are many possible reasons and you need to check with your web developer toolset if that is because of a client side code, cached permanent redirects, deep link protection, serverside URL rewrite rules or something else. See for example; https://serverfault.com/a/561897/546643

Bob
  • 5,335
  • 5
  • 24
  • Hey man, thanks for the reply, the redirect is still happening, I have added the `vhosts` config for target subdomain as well. Can you look again please. Thanks – Sahil Mar 04 '21 at 13:33
  • There isn't anything obvious wrong or missing in the Apache configuration, but there might be `.htaccess` files and such . – Bob Mar 04 '21 at 15:57
  • I just looked for the .htaccess file, apparently there isn't any in the bitnami's ghost blog instance, any idea if I could put something there that will help me here? – Sahil Mar 04 '21 at 18:00