0

I have an Apache web server that also runs my Gitlab server and now I'm trying to make it a mail server too. Various tutorials told me that I needed to start with adding some DNS entries and getting those cleared with Spamhaus. So I logged into GoDaddy and I made these records:

A      @      (my Amazon elastic IP)
A      gitlab (my Amazon elastic IP)
A      mail   (my Amazon elastic IP)
CNAME  www    @
MX     @      mail.example.com

Does that look normal so far? Besides that I have some mandatory NS and SOA records.

Previously, I had my httpd.conf file set up to handle my gitlab subdomain and redirect http to https. But now for some reason I'm able to browse to mail.example.com and it takes me to my gitlab.example.com login page. This is extremely vexing because I never even entered the mail subdomain as a VirtualHost in my httpd.conf file. Now I'm trying unsuccessfully to get rid of it. This is the relevant section of my httpd.conf:

Listen 80
ServerName example.com
DocumentRoot "/var/www/html"

<VirtualHost *:80>
  ServerName gitlab.example.com
  ServerAlias gitlab.example.com
  ServerSignature Off

  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^gitlab.example.com$
  RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
  RewriteCond %{SERVER_NAME} =gitlab.example.com
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
  ServerName mail.example.com
  RedirectPermanent / https://example.com:443
</VirtualHost>


<VirtualHost *:443>
  SSLEngine on
  SSLProtocol all -SSLv2
  SSLHonorCipherOrder on
  SSLCipherSuite "...(a bunch of letters and numbers)..."
  Header add Strict-Transport-Security: "max-age=15768000;includeSubdomains"
  SSLCompression Off
  SSLCACertificateFile /etc/httpd/ssl.crt/cert.pem
  ServerName gitlab.example.com
  ServerAlias gitlab.example.com
  ServerSignature Off

  ProxyPreserveHost On

  AllowEncodedSlashes NoDecode

  <Location />
    Require all granted

    ProxyPassReverse http://127.0.0.1:8181
    ProxyPassReverse http://gitlab.example.com/
  </Location>

    RewriteEngine on
    RewriteCond %{REQUEST_URI> ^/api/v3/.*
    RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]

    (Locations of error documents, logs, certificates...)
</VirtualHost>

Can anyone look at that and tell my why mail.mydomain redirects to my Gitlab? I would prefer that it just not go anywhere except maybe to a 404 error.

  • Maybe changing A mail (my Amazon elastic IP) to something else then your ip would have the desired effect. – Don King Jan 3 at 15:15
1

Your gitlab VirtualHost is the first one. Under Apache, the first virtual host that you have configured is the catch-all. If nothing specific matches, Apache uses the first one.

My guess is that now that you have added the specific virtual host for mail, everything is configured correctly. However, the redirect that you got before you added a specific virtual host for it is now cached by your browser. All you need to do is clear your browser cache.

I also recommend adding a better catch-all virtual host. It is fine to have a first virtual host that does nothing but show 404 errors for any unrecognized server name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.