Good days people
I’m running a webserver on port 80 and and email server on port 82 on the same server over home ADSL.
I have a primary domain example.com as an A-record with www.example.com as a CNAME to example.com. I have configured apache so that both domains using both ports 80 & 82 to redirect to the mail server.
example.com:80 --> mail server
example.com:82 --> mail server
www.example.com:80 --> mail server
www.example.com:82 --> mail server
This is all “working” as it should and as the way I want it – I think…
Now I have a subdomain exclude.example.com that I struggle with. I’m trying to configure both exclude.example.com to access the web server on both port 80 and 82.
exclude.example.com:80 --> web server
exclude.example.com:82 --> web server
but currently exclude.example.com:82 is still redirecting to the mail server.
Below is my apache config
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
RewriteEngine on
#RewriteCond %{HTTP_HOST} example.com [NC]
RewriteCond %{HTTP_HOST} !exclude.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com:82 [L,R=301]
</VirtualHost>
<VirtualHost *:80>
ServerName exclude.example.com
ServerAlias exclude.example.com
DocumentRoot "${INSTALL_DIR}/www/exclude/"
<Directory "${INSTALL_DIR}/www/exclude/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:82>
ServerName exclude.example.com
Redirect / https://www.example.com
</VirtualHost>
2
Answers
You have to add serveralias to last virtualhost entry as well, see below.
Also you are redirecting to https://www.example.com, instead you should setup this also as you have setup *:80 virtual instead of redirection.
If the web server is listening on port 80 while the mail server is listening on port 82, an apache redirect won’t work as apache is not listening on port 82. Also can’t have 2 services using the same port.