Learn about Centmin Mod LEMP Stack today
Register Now

Is it possible to have two domains listen to 1 IP?

Discussion in 'Domains, DNS, Email & SSL Certificates' started by Jon Snow, Jan 13, 2022.

  1. Jon Snow

    Jon Snow Active Member

    628
    120
    43
    Jun 30, 2017
    Ratings:
    +179
    Local Time:
    4:10 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    I have a server that hosts 2 websites (Website A & Website B) with 2 IPs (IP A & IP B).
    Website A uses IP A.
    Website B uses IP B.


    I want to add a 3rd domain/website to IP B.

    I used this guide to add the third domain so that I'd have the Letsencrpt SSL cert immedinately - Using Centmin Mod acmetool.sh addon for Nginx HTTP/2 based HTTPS with free Letsencrypt SSL certificates

    Is it possible to configure the 3rd domain to listen to IP B?

    I tried but the 3rd domain keeps redirecting to Website B.

    If it helps, IP A & IP B redirect to their respective websites when I enter them into the web browser. I don't see a default nginx centminmod page.

    Or would I need to get a 3rd IP for the third website?
     
  2. eva2000

    eva2000 Administrator Staff Member

    47,851
    10,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,961
    Local Time:
    6:10 AM
    Nginx 1.21.x
    MariaDB 10.x
    Provided your second or additional IPs are already configured by your web host and/or yourself (post 1 of thread) and the ping or connect properly to your server, the you should be able to use Centmin Mod's SECOND_IP persistent variable to override the default server IP when creating new Centmin Mod Nginx vhosts via centmin.sh menu option 2, 22 or nv or addons/acmetool.sh command line as outlined at
    https://community.centminmod.com/threads/adding-additional-ip-addresses.11816/#post-50297

    . The link also outlines how you can manually edit an existing Centmin Mod Nginx vhost to listen to a specific IP address already registered and working on your server.

    If you have a 3rd or more more IPs, you can just edit SECOND_IP variable again BEFORE running centmin.sh menu option 2, 22 or nv or addons/acmetool.sh command line to create the intended Nginx vhost with a specific IP address on listen directive.
     
  3. Jon Snow

    Jon Snow Active Member

    628
    120
    43
    Jun 30, 2017
    Ratings:
    +179
    Local Time:
    4:10 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    I see the second IP (IP B) there.

    These are the guides I followed to set it up in the past.

    But if I try to add another website to IP B (the IP defined in SECOND_IP via custom_config), when I visit the 3rd domain name it goes to Website B instead of the files I uploaded to the 3rd domain path.

    https://community.centminmod.com/threads/rdns-and-spf.22359/#post-91590
    In this post, Website A also sends emails from IP B when it really should be IP A.

    Maybe I did something wrong?
     
  4. eva2000

    eva2000 Administrator Staff Member

    47,851
    10,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,961
    Local Time:
    6:10 AM
    Nginx 1.21.x
    MariaDB 10.x
    make sure the DNS is proper updated to point to the right IP referenced in each Nginx vhost's listen directive /usr/local/nginx/conf/conf.d/yourdomain.com.conf (non-HTTPS) and /usr/local/nginx/conf/conf.d/yourdomain.com.ssl.conf (HTTPS) config files. If a server{] context doesn't have a listen directive set, it will default to default server IP, so if it's missing a listen directive in server{} context, you need to specifically add a listen directive for that IP.
     
  5. Jon Snow

    Jon Snow Active Member

    628
    120
    43
    Jun 30, 2017
    Ratings:
    +179
    Local Time:
    4:10 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    I found the issue.

    When I run the script from Using Centmin Mod acmetool.sh addon for Nginx HTTP/2 based HTTPS with free Letsencrypt SSL certificates

    It deletes my domain.conf and changes it to domain.ssl.conf which has:
    Code (Text):
    listen IP-B:443 ssl http2 reuseport;

    If I remove ssl http2 reuseport, Website C loads as intended. If I add it back, Website B loads instead.

    What's the purpose of ssl http2 reuseport and do I need it for SSL?
     
  6. eva2000

    eva2000 Administrator Staff Member

    47,851
    10,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,961
    Local Time:
    6:10 AM
    Nginx 1.21.x
    MariaDB 10.x
    don't remove all thsoe options try only removing reuseport and see
     
  7. Jon Snow

    Jon Snow Active Member

    628
    120
    43
    Jun 30, 2017
    Ratings:
    +179
    Local Time:
    4:10 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Can confirm that only reuseport was the issue.