Welcome to Centmin Mod Community
Register Now

Nginx New domain vhost redirected to existing domain on the server

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by trxerz, Aug 7, 2021.

Tags:
  1. trxerz

    trxerz Member

    68
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    7:56 PM
    • CentOS Version: CentOS 7 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: i.e. 1.21.0
    • PHP Version Installed: i.e. 7.4.21
    Hi @eva2000

    Currently, my VPS has 2 IPs for my 2 domains, so each domain is pointed with an A record with separate IP. No problem here.

    For illustration: 1st domain AAAAA.com with IP 111.111.111.111
    Code:
    server {
      listen 111.111.111.111:80;
      server_name aaaaa.com www.aaaaa.com;
      return 301 https://www.aaaaa.com$request_uri;
    }
    
    server {
      listen 1111.111.111.111:443 ssl http2 reuseport;
      server_name aaaaa.com www.aaaaa.com;
    .....
    }
    
    2nd domain BBBBB.com with IP 222.222.222.222
    Code:
    server {
      listen 222.222.222.222:80;
      server_name bbbbb.com www.bbbbb.com;
      return 301 https://www.bbbbb.com$request_uri;
    }
    
    server {
      listen 222.222.222.222:443 ssl http2 reuseport;
      server_name bbbbb.com www.bbbbb.com;
    .....
    }
    


    Now I have difficulty adding my 3rd domain CCCCC.com which pointed with an A record to 222.222.222.222 IP address.


    First try:
    Code:
    server {
      listen 222.222.222.222:80;
      server_name ccccc.com www.ccccc.com;
      return 301 https://ccccc.com$request_uri;
    }
    
    server {
      listen 222.222.222.222:443 ssl http2 reuseport;
      server_name ccccc.com www.ccccc.com;
    .....
    }
    
    RESULT:
    Code:
    nginx: [emerg] duplicate listen options for 222.222.222.222:443 in /usr/local/nginx/conf/conf.d/bbbbb.com.conf:9
    I try to remove the IP on the listen
    Code:
    server {
      listen 80;
    .....
    }
    
    server {
      listen 443 ssl http2 reuseport;
    ......
    
    Nginx successfully restarts but my 3rd domain CCCCC.com redirected to BBBBB.com. Maybe because A record pointed to 2nd IP.

    Can anyone explain what I should do? I don't know much about nginx, especially with more than 1 IP in the same server.

    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    47,294
    10,705
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,631
    Local Time:
    4:56 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    reuseport can only be used in listen directive once per ip port pairing. So for third and subsequent nginx vhosts ensure reuseport is not listed in listen directives. Centmin Mod can detect this for single IP defaults but not if you use second IP though I think I added some checks for auto created nginx vhosts but this won't apply if you are manually creating ngi
     
  3. trxerz

    trxerz Member

    68
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    7:56 PM
    Thanks, it works now. Can I remove the reuseport for the second IP too? Is there any advantage to using reuseport?