Apache - Accessing Web Gui via alternate hostname

Is there a specific way to allow Freepbx web gui to be accessible via alternate hostnames?

Example:

2 freepbx v17 servers exist, the system hostnames are pbx0.example.com pbx1.example.com.
pbx1.example.com is a backup in case something happens to pbx0.example.com.
However, the DNS / url for registering phones is just pbx.example.com and it points to the IP of pbx0 or pbx1 depending on which one is the active server.
We’re trying to access the admin interface of either one based on the systems hostname.

These 2 apache files have the url pbx.example.com hardcoded into them:
/etc/apache2/sites-available/sangoma.conf
/etc/apache2/sites-available/sangoma-ssl.conf

This makes it so that if you try to access the admin interface via https://pbx0.example.com or https://pbx1.example.com, you will always get forwarded to https://pbx.example.com (which is always the active server).

To resolve this we modified the RewriteRule’s in ‘/etc/apache2/sites-available/sangoma.conf’, replacing pbx.example.com with %{HTTP_HOST}
old: RewriteRule ^/(.) “https://pbx.example.com:443/”
new: RewriteRule ^/(.
) “https://%{HTTP_HOST}:443/”
In /etc/apache2/sites-available/sangoma-ssl.conf, we replaced all ServerName entries with ‘ServerAlias *:’
old: ServerName pbx.example.com:443
new: ServerName *:443

These 2 apache files are automatically generated so they get overwritten.
Is there a way to override this or another way to accomplish what we are trying to do?

Thanks!

Apache loads in alphabetical order so just add a /etc/apache2/sites-available/zzz-domain.conf with your configs.

Don’t forget to

  • a2ensite zzz-domain.conf
  • apache2ctl configtest
  • systemctl reload apache2

“Custom domain mapping” may be a good feature request.

An alternative that requires another server is to do a reverse proxy. Currently you can map services by port on FreePBX. You could do something like below:

Thanks @jfinstrom for the ideas.
I’m looking for something that will get backed up and restored via the backup module so the nginx proxy option is not going to work well for me.

I’m not sure that custom apache configs will get backed up with the backup module, I’ll be testing that soon. Looks like the sangoma.conf file with the redirects did not get backed up and restored properly.

I did find that modifying the ServerName in sangoma-ssl.conf does not seem to be required.
Only the redirects in sangoma.conf need to be updated.

There is also a setting under ‘System Admin > Port Management’ called “HTTPS Address” which controls the url in the rewrite line of sangoma.conf.
Unfortunately it only accepts a fqdn. If it could accept apache aliases like ‘%{HTTP_HOST}’ then it would be perfect.

I’ll take a look at the issue tracker and create a new one.
Thanks.

I was able to update the database to use %{HTTP_HOST} and then regenerate the configs:

mysql -u root
update asterisk.sysadmin_options set value=“%{HTTP_HOST}” where key=“HTTP_HOST”;
su -l asterisk
php /var/www/html/admin/modules/sysadmin/hooks/update-ports

Also, I just found in the backup a “Custom Files” setting where you can add custom files/folders to be backed up.

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