I'm facing an issue with virtual host and Apache in general. What I'm missing is more an explanation of the big picture of how it works rather than one specific command, let me explain:
I have a single domain my.domain with one SSL cert associated to it. I cannot generate certificate for sub domain like toto.my.domain.
I have 4 services running:
- Zabbix running with Apache on port 443 and located in /usr/share/zabbix
- Nextcloud running with Apache on port 443 and located in /var/www/html/nextcloud
- Transmission running on its own webserver on port 9091 and located in /usr/share/transmission
- Emby running on its own webserver on port 8096 (http) and 8920 (https) and located God knows where
I created 4 configuration files in the sites-available folder. For Zabbix and Nextcloud, these are not vhost, just configuration with Alias and Directory directives.
- For Zabbix Alias /zabbix /usr/share/zabbix
- For Nextcloud Alias /nextcloud "/var/www/html/nextcloud/"
With this configuration, I can access Zabbix through https://my.domain/zabbix and Nextcloud through https://my.domain/nextcloud
For Emby and Transmission I want to access it through:
So I script-kiddy copy pasted the following vhost confs from the internet which seem to work for everyone.
For Transmission
<VirtualHost *:443>
ServerName my.domain
ServerAlias www.my.domain
Redirect permanent /transmission https://my.domain/transmission
RewriteEngine on
RewriteRule /transmission[/]?$ /transmission/web/ [R]
ProxyRequests On
ProxyPreserveHost Off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass /transmission http://127.0.0.1:9091/transmission
ProxyPassReverse /transmission http://127.0.0.1:9091/transmission
</Virtualhost>
<VirtualHost *:80>
ServerName my.domain
ServerAlias www.my.domain
Redirect permanent /transmission https://my.domain/transmission
</Virtualhost>
For Emby
<VirtualHost *:80>
ServerName my.domain
Redirect permanent /emby https://my.domain/emby
</VirtualHost>
<VirtualHost *:443>
ServerName my.domain
RewriteEngine on
RewriteRule ^/emby$ /emby/ [R]
<proxy *>
Order Allow,Deny
Allow from all
</proxy>
ProxyRequests Off
ProxyPreserveHost On
Header set Connection "Upgrade"
RequestHeader setifempty Connection "Upgrade"
Header set Upgrade "websocket"
RequestHeader setifempty Upgrade "websocket"
# Notice!!! Put me before http!!!
ProxyPass /socket ws://localhost:8096/socket
ProxyPassReverse /socket ws://localhost:8096/socket
# Notice!!! Put me after ws!!!
ProxyPass / http://localhost:8096/
ProxyPassReverse / http://localhost:8096/
</VirtualHost>
The issue is that since I only have one domain name, I don't get the point of creating "vhost" which are in fact not real vhost. In my case, Zabbix and Nextcloud are not Vhost and Emby and Transmission share the same domain name so we can't say these are Vhost am I right ?
The consequence of these configuration is that if I enable transmission first, it works but Emby doesn't. I got the message You don't have permission to access /emby
If I enable Emby first, Emby works but Transmission doesn't. And I got the message You don't have permission to access /transmission/web/
After reading this https://httpd.apache.org/docs/2.4/vhosts/name-based.html and the specific statement I understand the behavior of Apache "If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.".
That's why Emby is working if I enable it first, and same goes if I enable Transmission first.
So the last question is : how to fix it !?
Thanks in advance for any hints !