Join the community today
Register Now

Nginx Make IP Address redirect to domain

Discussion in 'Centmin Mod Insights' started by xaitmi, Jan 18, 2015.

  1. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    2:24 AM
    Hi.
    I deleted the default stuff as per the instructions in this thread Proper way to remove the default account ? | Centmin Mod Community

    Currently I have

    my.mydomain.com = my billing system
    and
    mydomain.com = a front end for my website

    Both sites work great.

    My issue is if I go to my vps's ip address in my browser it shows the nginx test page.

    How can I make it so that if someone enters my VPS ip in their browser, it will take them to mydomain.com
     
  2. eva2000

    eva2000 Administrator Staff Member

    29,016
    6,585
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,775
    Local Time:
    4:24 PM
    Nginx 1.13.x
    MariaDB 5.5
    FYI, in most cases for proper Centmin Mod Nginx operation the server_name in virtual.conf pertaining to default hostname of server should always been default_server for main ip address as alot of Centmin Mod addons like phpmyadmin, linfo and default stats pages for APC Cache, Xcache and Zend Opcache and Memcache rely on serving from default server hostname.domain.com/* which would have public web root at /usr/local/nginx/html.

    Of course you can move those stats pages elsewhere and change default_server if you want. Just know that Centmin Mod updates or fixes or improvements won't know where to do future automatic updates for those features or components if you do move them.

    Probably better to have a 2nd IP address which you do actual web site hosting on and leave main server IP for default hostname.

    Or ghetto work around would be in default hostname's virtual.conf with public web root at /usr/local/nginx/html edit the index.html to refresh redirect to yourdomain.com that would leave rest of default hostname's setup intact
     
    Last edited: Jan 18, 2015
  3. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    2:24 AM
    Thanks for the advice.
    Luckily my VPS does have 2 ip addresses, never used the other one before.
    Going to do some research now on how to make my websites use the other ip address.
     
  4. eva2000

    eva2000 Administrator Staff Member

    29,016
    6,585
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,775
    Local Time:
    4:24 PM
    Nginx 1.13.x
    MariaDB 5.5
  5. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    2:24 AM
    Got it working on the new IP.

    Just wanted to point out that putting

    listen ipaddr 80;

    the 80 breaks it.

    nginx: [emerg] invalid parameter "80" in /usr/local/nginx/conf/conf.d/my.mydomainhere.com.conf:10

    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

    removing the 80 and just doing

    listen ipaddr;

    makes it work fine.

    ----
    Also I was wondering what is the default directory for the second ip be? Because it looks like it's not getting it's content from /usr/local/nginx/html

    I want to make the 2nd ip go to mydomain.com if anyone enters it into the browser.
     
  6. eva2000

    eva2000 Administrator Staff Member

    29,016
    6,585
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,775
    Local Time:
    4:24 PM
    Nginx 1.13.x
    MariaDB 5.5
    that's because default vhosts's virtual.conf already has mainip listening on port 80

    check out Getting Started Guide at Getting Started with Centmin Mod which explains the relationship between server's default hostname's virtual.conf vhost and rest of vhosts created via centmin.sh menu option 2 (particularly last sentence of page) :)

    or if you want edit the centmin.sh menu option 2 add vhost's default vhost template in inc/nginx_addvhost.inc from lines 47 to 93 in .07 stable so to add a specific 2nd ipaddress's listen directive

    line 47 to 57 of inc/nginx_addvhost.inc with added secondipaddress
    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    #server {
    #            listen yoursecondipaddress 80;
    #            server_name $vhostname;
    #            return 301 \$scheme://www.${vhostname}\$request_uri;
    #       }
    
    server {
      listen yoursecondipaddress 80;
      server_name $vhostname www.$vhostname;
    that way everytime you add a new nginx vhost via centmin.sh menu option 2, it uses the 2nd ip address by default
     
    • Like Like x 1
  7. quicksalad

    quicksalad Member

    159
    9
    18
    May 31, 2015
    Ratings:
    +13
    Local Time:
    11:54 AM
    is it okay to leave the server IP pointer to nginx test page? I have only 1 static IP and cannot do the second option suggested above. I don't want to use redirect, is there any other options and suggestions? Thanks
     
  8. eva2000

    eva2000 Administrator Staff Member

    29,016
    6,585
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,775
    Local Time:
    4:24 PM
    Nginx 1.13.x
    MariaDB 5.5
    perfectly fine to do so - nearly all my vps are setup this way as Centmin Mod has stats pages etc that work off the main hostname and ip so you can directly access them via ip or hostname i.e. PHP Opcode and Memcached statistics pages | Centmin Mod Community
     
    • Informative Informative x 1
  9. quicksalad

    quicksalad Member

    159
    9
    18
    May 31, 2015
    Ratings:
    +13
    Local Time:
    11:54 AM
    just saw your IP redirected on nginx test page. Thanks for clearing @eva2000 :)