0

I have two web servers nginx and apache2. I have an A record for mail.aboutryansam.com and a CNAME webmail.aboutryansam.com. I've been trying to setup a postfix and dovecot mail server hosted on mail.aboutryansam.com and a roundcube mail client hosted on webmail.aboutryansam.com. I'm runnig Ubuntu 18. I have two dir /var/www/nginx/mail.aboutryansam.com/ for the mail server. And I have /var/www/html for roundcube. By default apache2 and nginx run on the same port so I changed nginx to use port 81. I have the default html page in the apache dir and I made a custom one in my nginx dir. When I visit mail.aboutryansam.com it still takes me to the apache html page but I have the conf file to work off the nginx dir

server {
  listen 81;
  server_name mail.aboutryansam.com;

  location {
    root /var/www/nginx/mail.aboutryansam.com
    index index.html index.htm;

    # proxy_pass http://localhost:3010;
    # proxy_set_header Host $host;
    # proxy_set_header X-Real-IP $remote_addr;
  }
}

I'm having lots of trouble running web servers and I'm new to server administration so sorry If I couldn't explain it well enough. If you can help me with and answer, please be "--verbose" as I said I'm new to this stuff.

Ryan Sam
  • 103
  • 3

1 Answers1

1

DNS A records point to IP addresses, not services. A service like Apache/nginx can be reached by the IP address of the machine it's running on AND the port.

When you enter http://mail.aboutryansam.com in your browser it connects to the default HTTP port 80, so you connect to 198.58.105.140:80 where Apache is listening. The server_name you defined in nginx is not taken into consideration at this point, because the request already entered Apache.

If you want to connect to a service listening on port 81 you have to explicitely specify this: http://mail.aboutryansam.com:81

If you don't want this :81 in the URL, your options are:

  • Set up a reverse proxy to port 81 on the server at port 80 -
  • If you have multiple machines / IPs available, bind Apache & nginx on distinct ones, so both can bind port 80, and change the DNS records accordingly
Tobias K.
  • 126
  • 1
  • 1
  • 4
  • Should the proxy_pass that I have commented out work? – Ryan Sam Sep 09 '18 at 21:52
  • You need the proxy setup on the server on port 80 if you want to omit the port. Generally the `proxy_pass` looks OK, if you manage to get there. If you only want to proxy to 3010, Apache can do this aswell, no need for nginx here, just create another VHost. – Tobias K. Sep 09 '18 at 22:00