Switching wordpress to virtual hosts gives me default page, second virtual host gives me ssl warning

Keywords: WordPress - Google Cloud Platform - Technical issue - Application configuration

bnsupport ID: dff518d5-6c5b-d6c7-3d02-f04272c6fa13

bndiagnostic output:

? Resources: Found possible issues
https://docs.bitnami.com/installer/faq/linux-faq/administration/increase-memory-linux/

bndiagnostic failure reason: The suggested guides are not related with my issue

Description:
Hi, I’ve read many discussions on similar issues but I can’t seem to figure it out.

I’m trying to do two things

  1. Switch my wordpress install into a virtual host (i.e. domain1)
  2. Setup a second custom app in another virtual host (i.e. domain2)

Issues for #1
When I comment out in /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf
the line /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf

I get the default bitnami page when I visit my domain1
i.e. “Awesome! WordPress is now installed.”

Issue for #2
I’m getting a warning that domain2 is using the certificate from domain1

My config

/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf

# Bitnami applications installed in a prefix URL
#Include "/opt/bitnami/apps/wordpress/conf/httpd-prefix.conf"
Include "/opt/bitnami/apps/phpmyadmin/conf/httpd-prefix.conf"
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"

/opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName domain1.comm
    ServerAlias www.domain1.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

    # BEGIN: Enable HTTP to HTTPS redirection
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^domain1.com
    RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    # END: Enable HTTP to HTTPS redirection

    Alias /.well-known/ "/opt/bitnami/apps/letsencrypt/.well-known/"
    <Directory "/opt/bitnami/apps/letsencrypt/.well-known">
        Options +MultiViews
        AllowOverride None
        Require all granted
    </Directory>

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

<VirtualHost *:443>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/domain1.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/domain1.com.key"

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

/opt/bitnami/apps/domain2/conf/httpd-app.conf

RewriteEngine On
RewriteRule /<none> / [L,R]

<Directory "/opt/bitnami/apps/domain2/htdocs">
    Options +MultiViews +FollowSymLinks
    AllowOverride None
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>

    # BEGIN: Enable HTTP to HTTPS redirection
    RewriteEngine On
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    # END: Enable HTTP to HTTPS redirection
</Directory>

/opt/bitnami/apps/rigelblu/conf/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName domain2.com
    DocumentRoot "/opt/bitnami/apps/domain2/htdocs"
    Include "/opt/bitnami/apps/domain2/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:433>
    ServerName domain2.com
    DocumentRoot "/opt/bitnami/apps/domain2/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/domain2.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/domain2.com.key"
    Include "/opt/bitnami/apps/domain2/conf/httpd-app.conf"
</VirtualHost>

Forgot to mention. Thank you in advance for any help. It’s greatly appreciated.

I should mention, from reading other threads

I have not modified
/opt/bitnami/apache2/conf

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

And ServerName is localhost
/opt/bitnami/apache2/conf/

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80

The way i understand is

  1. Apache checks the default virtual host (bitnami.conf)
  2. If it doesn’t find a matching server name, it checks the virtual hosts

The thing I can’t figure out why visiting domain1 gives the results from the default virtual host instead of the configure domain1 virtual host

I fixed my first issue. Double “m” in here.
I also misspelled the domain name in the virtual host 443 section :slight_smile:

I found my second error. It should be 443, not 433.
I’ll post my final steps in case it helps anyone

Here’s the final steps I did to setup virtual hosts for Wordpress and new Custom App.
Hopefully it helps someone

  1. Create app directory
sudo mkdir /opt/bitnami/apps/domain2
sudo mkdir /opt/bitnami/apps/domain2/conf
sudo mkdir /opt/bitnami/apps/domain2/htdocs

sudo chown bitnami /opt/bitnami/apps/domain2/conf/
sudo chown bitnami:daemon /opt/bitnami/apps/domain2/htdocs/
sudo chmod 774 /opt/bitnami/apps/domain2/htdocs/
  1. Auto-Configure with Bitnami’s “Let’s Encrypt Certificate”
sudo /opt/bitnami/bncert-tool

Domain list []: domain2.com

# This will create two files domain2.com.crt and domain2.com.key
ls -l /opt/bitnami/apache2/conf
sudo chmod 600 /opt/bitnami/apache2/conf/domain2.com.*
  1. Revert bitnami’s apache’s config change (it’s unnecessary)
sudo vi /opt/bitnami/apache2/conf/httpd.conf
-ServerName domain2.com:80
+ServerName localhost:80
  1. Create httpd-app.conf
cd /opt/bitnami/apps/domain2/conf
sudo vi httpd-app.conf
httpd-app.conf
RewriteEngine On
RewriteRule /<none> / [L,R]

<Directory "/opt/bitnami/apps/domain2/htdocs">
    Options +MultiViews +FollowSymLinks
    AllowOverride None
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>
</Directory>
  1. Optional: Setup app prefix so application can be access through
    http://domain2.com
sudo vi httpd-prefix.conf
httpd-prefix.conf
Alias /app/ "/opt/bitnami/apps/domain2/htdocs/"
Alias /app "/opt/bitnami/apps/domain2/htdocs"

Include "/opt/bitnami/apps/domain2/conf/httpd-app.conf"
  1. Setup virtual host for app
sudo vi httpd-vhosts.conf
httpd-vhosts.conf
<VirtualHost *:80>
    ServerName domain2.com
    ServerAlias www.domain2.com
    DocumentRoot "/opt/bitnami/apps/domain2/htdocs"

    # BEGIN: Enable HTTP to HTTPS redirection
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^localhost
    RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    # END: Enable HTTP to HTTPS redirection

    Alias /.well-known/ "/opt/bitnami/apps/letsencrypt/.well-known/"
    <Directory "/opt/bitnami/apps/letsencrypt/.well-known">
        Options +MultiViews
        AllowOverride None
        Require all granted
    </Directory>

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

<VirtualHost *:443>
    ServerName domain2.com
    ServerAlias www.domain2.com
    DocumentRoot "/opt/bitnami/apps/domain2/htdocs"

    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/domain2.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/domain2.com.key"

    Include "/opt/bitnami/apps/domain2/conf/httpd-app.conf"
</VirtualHost>
  1. Tell bitnami not to use the prefix wordpress config, we’ll switch it to a virtual host
sudo vi /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf

# Comment out this line
#Include "/opt/bitnami/apps/wordpress/conf/httpd-prefix.conf"
  1. Tell bitnami about our app virtual host
sudo vi /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf

# Add these two lines
Include "/opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf"
Include "/opt/bitnami/apps/domain2/conf/httpd-vhosts.conf"
  1. Update wordpress virtual host config
<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

    # BEGIN: Enable HTTP to HTTPS redirection
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^localhost
    RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    # END: Enable HTTP to HTTPS redirection

    Alias /.well-known/ "/opt/bitnami/apps/letsencrypt/.well-known/"
    <Directory "/opt/bitnami/apps/letsencrypt/.well-known">
        Options +MultiViews
        AllowOverride None
        Require all granted
    </Directory>

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

<VirtualHost *:443>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/domain1.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/domain1.com.key"

    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
  1. Update file permissions and restart apache
sudo chown bitnami /opt/bitnami/apps/domain2/conf/*
sudo chown bitnami:daemon /opt/bitnami/apps/domain2/htdocs/*
sudo chmod 600 /opt/bitnami/apache2/conf/domain2.com*

sudo /opt/bitnami/ctlscript.sh restart apache
  1. Move application into app directory
/opt/bitnami/apps/domain2/htdocs/
1 Like

Hello @tom.hosiawa,

I’m glad you managed to solve this issue and get it running. Also, thanks for sharing your solution with the community and helping other users! If there is no longer an issue with this we can mark your last post as the solution and close this thread.

If you encounter any other problem, please do not doubt to open a new thread.

Regards,
Francisco de Paz

1 Like