Lightsail second vhost is pulling original vhost

Keywords: General - AWS - Technical issue - Other
Description:
I setup a new Wordpress instance on Lightsail and attempted to add a second vhost for a simple hello world. But, the second vhost just routes directly to the initial wordpress instance.

I tried to follow the below instructions, but experiencing the issue mentioned above.

https://docs.bitnami.com/general/infrastructure/lamp/configuration/configure-custom-application/#understand-virtual-host-configuration-files

Hello @fischgeek,

We have a Support Tool that will gather relevant information for us to analyze your configuration and logs. Could you please execute it on the machine where the stack is running by following the steps described in the guide below?

Please note that you need to paste the code ID that is shown at the end.

Hey! Thanks for your reply. Here’s my code: bd2ff071-3ca8-27ad-8b6a-680de497ad60

Hello @fischgeek,

I just noticed that our support tool is not retrieving the vhost files (we will fix that). Probably the issue is related to ServerAlias *. You should differentiate them using different ServerName and ServerAlias so depending on how you access you can offer different content.

If you continue facing issues, please share with us the content of your vhost files.

Regards

Thanks @davidg. Here are my vhost files and some information on what I’ve done so far.

  • I started with a “WordPress” stack on lightsail.

  • I attempted to add an additional “myapp”

  • I noticed the default /opt/bitnami/apps/wordpress/conf did not have a httpd-vhosts.conf file. I created it and filled it out accordingly (below).

  • I moved the certs from /opt/bitnami/apache2/conf/ to /opt/bitnami/apps/wordpress/conf/certs

    • The /certs directory was already there for me
  • I made sure to include both vhosts files in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf`

    • So, now all three files (httpd-app.conf, httpd-prefix.conf, httpd-vhosts.conf) for both sites have includes in the necessary bitnami-apps-***.conf files.

App 1 (default WordPress installation)

~/apps/wordpress/conf/httpd-app.conf


RewriteEngine On

RewriteRule /<none> / [L,R]

<IfDefine USE_PHP_FPM>

    <Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>

</Proxy>

</IfDefine>

<Directory "/opt/bitnami/apps/wordpress/htdocs">

    Options +MultiViews +FollowSymLinks

    AllowOverride None

    <IfVersion < 2.3 >

        Order allow,deny

        Allow from all

    </IfVersion>

    <IfVersion >= 2.3>

        Require all granted

    </IfVersion>

<IfModule php7_module>

        php_value memory_limit 512M

</IfModule>

<IfDefine USE_PHP_FPM>

    <FilesMatch \.php$>

        SetHandler "proxy:fcgi://wordpress-fpm"

    </FilesMatch>

</IfDefine>

~/apps/wordpress/conf/httpd-prefix.conf


# App url moved to root

DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"

#Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"

RewriteEngine On

RewriteCond "%{HTTP_HOST}" ^ec2-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})\..*\.amazonaws.com(:[0-9]*)?$

RewriteRule "^/?(.*)" "%{REQUEST_SCHEME}://%1.%2.%3.%4%5/$1" [L,R=302,NE]

Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"

~/apps/wordpress/conf/httpd-vhosts.conf


<VirtualHost *:80>

    ServerName lightsail.fischgeek.com

    ServerAlias lightsail.fischgeek.com

    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"

</VirtualHost>

<VirtualHost *:443>

    ServerName lightsail.fischgeek.com

    ServerAlias lightsail.fischgeek..com

    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

    SSLEngine on

    SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/lightsail.fischgeek.com.crt"

    SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/lightsail.fischgeek.com.key"

    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"

</VirtualHost>

App 2 (myapp)

~/apps/myapp/conf/httpd-app.conf


<Directory /opt/bitnami/apps/myapp/htdocs/>

        Options +FollowSymLinks

        AllowOverride All

        <IfVersion < 2.3 >

        Order allow,deny

        Allow from all

        </IfVersion>

        <IfVersion >= 2.3>

        Require all granted

        </IfVersion>

</Directory>

~/apps/myapp/conf/httpd-prefix.conf


# App url moved to root

DocumentRoot "/opt/bitnami/apps/myapp/htdocs"

#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"

Alias /myapp "/opt/bitnami/apps/myapp/htdocs"

#Alias /myapp/ "/opt/bitnami/apps/myapp/htdocs"

#RewriteEngine On

#RewriteCond "%{HTTP_HOST}" ^ec2-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})\..*\.amazonaws.com(:[0-9]*)?$

#RewriteRule "^/?(.*)" "%{REQUEST_SCHEME}://%1.%2.%3.%4%5/$1" [L,R=302,NE]

Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"

~/apps/myapp/conf/httpd-vhosts.conf


<VirtualHost *:80>

        ServerName test.fischgeek.com

        DocumentRoot "/opt/bitnami/apps/myapp/htdocs"

        Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"

</VirtualHost>

Hi @fischgeek,

It seems you are forcing HTTPS redirection. However, you don’t have a VirtualHost section for port 443 for myapp. Apart from that, you should comment out the line Alias /myapp "/opt/bitnami/apps/myapp/htdocs".

Also, you need to comment out the Include lines from /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file and include the vhosts in /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf file as the doucummentaion says (you need to follow Approach B: Self-Contained Bitnami Installations):

https://docs.bitnami.com/aws/infrastructure/lamp/configuration/configure-custom-application/

Could you try those changes?

If that does not work, please try to share a new support output with us so we can try to check the latest changes of your files (hopefully it will gather all the information).

Regards

Hi @davidg,

The default wordpress installation was the apps/wordpress app that was preinstalled. That did have forced https redirect, but myapp however I wasn’t concerned with at the moment and just wanted to get something working.

I made the changes and restarted via sudo /opt/bitnami/ctlscript.sh restart but both sites are still unreachable.

@davidg - Unable to edit my post due to my current status apparently, so here’s my latest support tool output: 2d780fbf-d9c9-bc5e-d31a-ba274ad95f60

Thanks!

Hello @fischgeek,

I can see that test.fischgeek.com is showing the hello world message now.

You should comment out the line for myapp in apache2/conf/bitnami/bitnami-apps-prefix.conf:

Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"

For lightsail.fischgeek.com, you are forcing HTTPS access. However, you commented out these lines in apache2/conf/bitnami/bitnami.conf (please uncomment them):

#  DocumentRoot "/opt/bitnami/apache2/htdocs"
#  SSLEngine on

I hope it helps

Thanks for the help @davidg, but I’m not seeing both apps working. I applied everything you instructed, but I must be missing something. I’m losing hope and about to give up here. Why is this so complicated? Perhaps I should’ve just done a LAMP stack on Lightsail instead of trying to shortcut it with a WordPress loadout.

Hello @fischgeek,

It is difficult to find the root cause of the issue after several changes, and I understand the frustration of sending the support tool once and again after any changes, but it is the way we have to validate the configuration since we cannot access your machine.

LAMP is the best solution to install different PHP apps on top of them following these steps:
https://docs.bitnami.com/aws/infrastructure/lamp/administration/create-custom-application-php/

There, you could install WP module on top of it:
https://bitnami.com/redirect/to/1492360/bitnami-wordpress-5.7.2-0-module-linux-x64-installer.run

My suggestion would be to try a clean installation and always save a backup of files to recover in case anything gets broken.

Regards

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.