Continuation of question on Virtual Host configuration

Keywords: LAMP/MAMP/WAMP - AWS - Technical issue - Services (Apache, MariaDB, MySQL…)

bndiagnostic ID: 19ac6e87-9c21-1f73-f8f4-6cd14923cf53

bndiagnostic output:

? Apache: Found possible issues
https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-errors-apache/

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

Description:
This is a continuation of a question I didn’t get to complete before I was called away to work on another project. Please view: Trying to set up many virtual hosts on one server

Jota told me where to put the virtual hosts file, but did not answer the question about whether what I had in the hosts file would work. It appears to not be working, and I don’t know where to look next.

The format I have:

## vaddhost: (mywebsite.org) at *:80
  <VirtualHost *:80>
        ServerName     mywebsite.org
        ServerAlias    www.mywebsite.org
        ServerAdmin    root@mywebsite.org
        DocumentRoot   "/opt/bitnami/apache/htdocs/mywebsite.org"
        CustomLog      "/opt/bitnami/apache/logs/mywebsite.org-access_log" combined
        ErrorLog       "/opt/bitnami/apache/logs/mywebsite.org-error_log"
    </VirtualHost>


The format in your sample file.

<VirtualHost 127.0.0.1:80 _default_:80>
  ServerAlias *
  DocumentRoot /opt/bitnami/projects/sample
  <Directory "/opt/bitnami/projects/sample">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>


What I have doesn’t seem to be working. An attempt combine the two didn’t work either:

## vaddhost: (mywebsite.org) at *:80
<VirtualHost 127.0.0.1:80>
    ServerName     mywebsite.org
    ServerAlias    www.mywebsite.org
    ServerAdmin    root@mywebsite.org
    DocumentRoot   "/opt/bitnami/apache/htdocs/mywebsite.org"
    CustomLog      "/opt/bitnami/apache/logs/mywebsite.org-access_log" combined
    ErrorLog       "/opt/bitnami/apache/logs/mywebsite.org-error_log"
  <Directory "/opt/bitnami/apache/htdocs/mywebsite.org">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>


I am stuck trying to get the 18 or so virtual hosts to work on the new server (LAMP packaged by Bitnami 8.0.15-1). I even tried changing the ServerName in httpd.conf to localhost:80 and that didn’t work.

Please review the virtual host code above and show me where I’ve gone wrong. Thank you!

Hi @Toolie ,

I just accessed some of your sites and they worked properly


As I mentioned in the previous thread, you need to include all your custom virtual hosts in a .conf file inside the vhosts folder as you did with the bitnami-sites-vhosts.conf one. I noticed you didn’t have the virtual hosts for the port 443, so please create a new file with those virtual hosts or recover the bitnami-sites-vhosts-ssl.conf.save file you already have in the vhosts folder.

Once you have all the domains configured, you should be able to access every site. As you do not have any wildcard in the ServerName/ServerAlias parameters, every request should be redirected to the specific virtual host.

Jota, the sites you’re seeing are on the OLD server. They are not working on the new server. I was unwilling to have the sites down while I tried to get the new server configured.

What does this mean?
“As you do not have any wildcard in the ServerName/ServerAlias parameters, every request should be redirected to the specific virtual host.”

If you mean that because I am not using the * wildcard, the requests should go where I intend them. They are not.

I have changed the WildBirdWingTips.com DNS to point to the new server so that you can see the non-working behavior. Here is the contents of the virtual hosts file:

## vaddhost: (wildbirdwingtips.com) at *:80
<VirtualHost *:80>
    ServerName     wildbirdwingtips.com
    ServerAlias    www.wildbirdwingtips.com
    ServerAdmin    root@wildbirdwingtips.com
    DocumentRoot   "/opt/bitnami/apache/htdocs/wildbirdwingtips.com"
    CustomLog      "/opt/bitnami/apache/logs/wildbirdwingtips.com-access_log" combined
    ErrorLog       "/opt/bitnami/apache/logs/wildbirdwingtips.com-error_log"
  <Directory "/opt/bitnami/apache/htdocs/wildbirdwingtips.com">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>
  1. Type in http://35.81.105.217/wildbirdwingtips.com with that configuration file active, and you get URL not found.
    image

  2. Disable the conf file above, restart Apache, and type in http://35.81.105.217/wildbirdwingtips.com, then the site appears. That’s how the site currently is configured, so if you check now, you’ll see the following:

So either something is wrong with the conf file above, or something is wrong elsewhere in my configuration. Where else do I look?

We need to investigate which virtual host Apache is using by default. That request is probably using the first VirtualHost you have in the bitnami-sites-vhosts.conf file so it tries to access “/opt/bitnami/apache/htdocs/belpresjustice.org/wildbirdwingtips.com/” and that doesn’t exist.

However, if you access http://wildbirdwingtips.com/ directly, it should work as expected. Is this correct?

Why is it trying to use that Virtual Host? As there is not any ServerName/ServerAlias using the * wildcard, there is no VirtualHost that matches the host/IP the request is using so it uses the first VirtualHost that is configured.

Why does it work when you disable the “bitnami-sites-vhosts.conf” file? Because the /opt/bitnami/apache2/conf/httpd.conf file uses the following configuration

IncludeOptional "/opt/bitnami/apache/conf/vhosts/*.conf"
Include "/opt/bitnami/apache/conf/bitnami/bitnami.conf"

As there is not a valid conf file in the vhosts folder, the “first” virtual host that is configured is the one in the bitnami.conf file and that one uses “/opt/bitnami/apache/htdocs” as DocumentRoot that is where wildbirdwingtips.com is.

As I was saying before, let’s try to obtain more info. Can you run these commands?

/opt/bitnami/apache/bin/apachectl -S
apachectl -S

They both should return the same info. Please post it here.

You are starting to understand my frustration; when I try to make the CONF file for WildBirdWingTips.com active, it fails.

The only other thing we’ve adjusted in the past is the ServerName in the httpd.conf file:

#ServerName www.tooliedotterpress.com:80 <-put there by LetsEncrypt script, change it back
ServerName localhost:80

I haven’t even gotten to the point where I can reinstate Let’s Encrypt, but I thought I’d mention it. Also, during my experimentation I disabled the default CONF file in the Virtual Hosts, 00_status-vhost.conf, in case that matters.

<VirtualHost 127.0.0.1:80>
  ServerName status.localhost
  <Location /server-status>
    Require local
    SetHandler server-status
  </Location>
</VirtualHost>

Here is the output you requested:

bitnami|~ $ /opt/bitnami/apache/bin/apachectl -S
VirtualHost configuration:
*:80                   localhost (/opt/bitnami/apache/conf/bitnami/bitnami.conf:6)
*:443                  localhost (/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf:15)
ServerRoot: "/opt/bitnami/apache"
Main DocumentRoot: "/opt/bitnami/apache/htdocs"
Main ErrorLog: "/opt/bitnami/apache/logs/error_log"
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/opt/bitnami/apache/logs/" mechanism=default
Mutex proxy-balancer-shm: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/opt/bitnami/apache/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: USE_PHP_FPM
User: name="daemon" id=1 not_used
Group: name="daemon" id=1 not_used
bitnami|~ $ apachectl -S
VirtualHost configuration:
*:80                   localhost (/opt/bitnami/apache/conf/bitnami/bitnami.conf:6)
*:443                  localhost (/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf:15)
ServerRoot: "/opt/bitnami/apache"
Main DocumentRoot: "/opt/bitnami/apache/htdocs"
Main ErrorLog: "/opt/bitnami/apache/logs/error_log"
Mutex ssl-stapling-refresh: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/opt/bitnami/apache/logs/" mechanism=default
Mutex proxy-balancer-shm: using_defaults
PidFile: "/opt/bitnami/apache/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: USE_PHP_FPM
User: name="daemon" id=1 not_used
Group: name="daemon" id=1 not_used
bitnami|~ $

What error do you get?

This is a good change, if you set tooliedotterpress.com as main domain, it’ll use the “default” virtual host when accessing that domain instead of the one created for it.

This should’t make any change.

Same as I said above: with the virtual hosts CONF file active (as it is now) for WildBirdWingTips.com, going to http://35.81.105.217/wildbirdwingtips.com this is the error I see:
image

So one could conclude that there’s something wrong in the layout of that CONF file. Thoughts?

Jota, any other ideas? I am at total work stoppage because of this.

Hi @Toolie ,

Can you run the Bitnami Diagnostic Tool again so I review the current configuration?

Sure, here you go: 516d7bb0-5954-5967-c275-055800cf12ab

Thank you!

Hi @Toolie,

I’m going to explain why your current configuration doesn’t work. The issue is easy to spot and resolve if you control the Apache’s configuration and how Apache works.

  • I can see you have a custom virtual host for http://wildbirdwingtips.com in the vhosts/wildbirdwingtips.com.conf file. What happens if I request that site?
❯ curl -LIk wildbirdwingtips.com
HTTP/1.1 301 Moved Permanently
Date: Thu, 24 Mar 2022 15:21:19 GMT
Server: Apache/2.4.52 (Unix) OpenSSL/1.1.1d
X-Powered-By: PHP/8.0.15
Expires: Wed, 17 Aug 2005 00:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: 9a466096d2bd6138ab1a13ae3f0f4f41=mh8f2npl8ac2r6j273n6c720rr; path=/; secure; HttpOnly
Location: https://wildbirdwingtips.com/
Last-Modified: Thu, 24 Mar 2022 15:21:19 GMT
Content-Type: text/html; charset=utf-8

HTTP/1.1 200 OK
Date: Thu, 24 Mar 2022 15:21:20 GMT
Server: Apache/2.4.52 (Unix) OpenSSL/1.1.1d
Last-Modified: Sun, 13 Mar 2022 23:16:10 GMT
ETag: "4a-5da21bfc9c280"
Accept-Ranges: bytes
Content-Length: 74
Vary: Accept-Encoding
Content-Type: text/html

The request is redirected to “https://wildbirdwingtips.com/” (WordPress, or the app you have in that domain, is performing that redirection). What’s the problem now? That you do not have a custom virtual host for https://wildbirdwingtips.com/ and the default one is used (bitnami/bitnami-ssl.conf). This one is not using /opt/bitnami/apache/htdocs/wildbirdwingtips.com as DocumentRoot and that’s why you do not see your app. What happens if I request https://wildbirdwingtips.com/wildbirdwingtips.com?

What’s the solution then?

I already told you to create the custom virtual host for https://wildbirdwingtips.com/. You can either create a new file (wildbirdwingtips.com-ssl.conf) or create the custom virtual host inside the current wildbirdwingtips.com.conf file. This block should work

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

  <Directory "/opt/bitnami/apache/htdocs/wildbirdwingtips.com">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

Extra: Why doesn’t http://IP/wildbirdwingtips.com work? The custom virtual host you created is using “*:80” so that one is also used when serving that request and the /opt/bitnami/apache/htdocs/wildbirdwingtips.com/wildbirdwingtips.com.conf folder doesn’t exist. More info here:

https://serverfault.com/a/567398

After some failed attempts and the complication of applying a Let’s Encrypt certificate, the virtual hosts are in fact working. Thank you for getting me to a solution, I am grateful.

Now I have a new problem: the .htaccess files used with my Joomla installations are not working; I cannot rely on them to rewrite the page URLs, many of which are links in use in my marketing materials that have already been distributed. Those links are now broken.
image

Here’s what is supposed to happen if you turn on use the .htaccess file:

https://www.mydomain.com/contact

With that internal rewriting turned off, the URLs become:

https://www.mydomain.com/index.php/contact

Those two URLs are not interchangeable.

Since you know the intricacies of my virtual host setup, can you look at the Joomla .htaccess file contents below and see if you can spot the reason why the rewriting is not working?


##
# @package    Joomla
# @copyright  (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
# @license    GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line 'Options +FollowSymLinks' may cause problems with some server configurations.
# It is required for the use of Apache mod_rewrite, but it may have already been set by
# your server administrator in a way that disallows changing it in this .htaccess file.
# If using it causes your site to produce an error, comment it out (add # to the
# beginning of the line), reload your site in your browser and test your sef urls. If
# they work, then it has been set by your server administrator and you do not need to
# set it here.
##

## No directory listings
<IfModule mod_autoindex.c>
  IndexIgnore *
</IfModule>

## Suppress mime type detection in browsers for unknown types
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
</IfModule>

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Disable inline JavaScript when directly opening SVG files or embedding them with the object-tag
<FilesMatch "\.svg$">
  <IfModule mod_headers.c>
    Header always set Content-Security-Policy "script-src 'none'"
  </IfModule>
</FilesMatch>

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations listed
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root home page
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment the following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

I did try removing the comment on the Rewrite Base / instruction which sometimes works, but this time it did not.

Do you see any instructions that might be causing this problem?

Hi @Toolie,

First of all, ensure all required virtual hosts have the “AllowOverride All” configuration line and the .htaccess file is inside the correct folder. Once you do that, in order to confirm the htaccess is working properly, and if the index.php redirection doesn’t work, you can test a redirection to a different site (for example google.com) to confirm Apache is reading the file properly. Once you confirm it, please review the htaccess file’s information and check the Apache’s official documentation to validate the different actions.

Thank you Jota. Adding the AllowOverride All didn’t fix the problem. I’ve never had to use it before with a Joomla installation. I’ll take this part of the question over to the Joomla forum. Thanks anyway!

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