Want more timely Centmin Mod News Updates?
Become a Member

Nginx Is it best to setup a vhost for the default domain?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by jeffwidman, Dec 5, 2014.

  1. jeffwidman

    jeffwidman Active Member

    152
    27
    28
    Dec 3, 2014
    Ratings:
    +51
    Local Time:
    1:03 PM
    I setup a DO droplet with hostname beta.somedomain.com, and setup the DNS A record for it.


    Did centminmod default install (#1). When I go to beta.somedomain.com in a browser, the server properly responds with the centminmod landing page.

    Is it recommended that I still setup a vhost for the domain? I don't anticipate putting other sites on this server; I might, but unlikely in the near future.

    Alternatively, I could switch the hostname to cloud1.somedomain.com and then setup a vhost for beta.somedomain.com...

    Reason why I ask is because it changes where the public web root for the domain is located on the server that I should upload my Xenforo files into...

    Update:
    I just tried creating a Vhost file in Centmindmod for beta.somedomain.com and it worked. This surprised me because I thought I read Centminmod will first check if Nginx is already handling a domain, and if so, won't create the vhost file for it.... but here it let me create a vhost file for beta.somedomain.com despite the server already properly responding at beta.somedomain.com??
     
    Last edited: Dec 5, 2014
  2. eva2000

    eva2000 Administrator Staff Member

    53,488
    12,130
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,671
    Local Time:
    6:03 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Best way to to setup nginx vhost for main hostname and your domains is via instructions at centminmod.com/download.html which link to Getting Started guide which explains how the main hostname vhost fits in with each of your domain's own Nginx vhost paths/public web root.

    Reason why that hostname duplicate worked is menu option 2 in centmin.sh checks for /home/nginx/domains/newdomain.com path. While main hostname is at /usr/local/nginx/html

    Following Getting Started guide is the best way forward, so you create new domains via centmin.sh menu option 2 to add new Nginx vhost and leave main hostname vhost untouched as it's used for other Centmin Mod installed stuff as well as for Centmin Mod adds like phpmyadmin installer and various statistics pages/urls etc for Nginx, PHP-FPM, PHP opcode cachers, memcached etc.
     
  3. jeffwidman

    jeffwidman Active Member

    152
    27
    28
    Dec 3, 2014
    Ratings:
    +51
    Local Time:
    1:03 PM
    I read the getting started guide carefully multiple times--last thing I want to do is waste your time when it's posted elsewhere. I've spent many hours reading through almost all the docs on this site, and really appreciate the time you've spent writing them up--I learned a lot, even about stuff that has nothing to do with my desired server setup, but was still interesting to read about.

    Unfortunately, even after all that, I'm still confused though--even after reading this post of yours.

    1) If I create a vhost with the same domain as the existing main hostname, which conf file gets read first?
    a) /home/nginx/domains/newdomain.com
    b) /usr/local/nginx/html​

    2) If both of the above files point at the same somedomain.com, will it create any conflicts?

    3) [quotee]leave main hostname vhost untouched as it's used for other Centmin Mod installed stuff as well as for Centmin Mod adds like phpmyadmin installer and various statistics pages/urls etc for Nginx, PHP-FPM, PHP opcode cachers, memcached etc.[/quote]

    So does this mean that I should be creating my droplet at cloud1.somedomain.com?

    And then create the additional vhost file for somedomain.com (since I want my forum located in a subdirectory on the root domain, not on a subdomain)?

    I think this means that if I wanted to access the server's opcache.php file that is looking at the opcache across all domains hosted on the site, then somedomain.com/xxx_opcache.php wouldn't work, and I'd have to use cloud1.somedomain.com/XXX_opcache.php correct? Or does php stick a /xxx_opcache.php on all domains addressed in all the vhost files?

    If I leave the hostname as somedomain.com and add a vhost file for somedomain.com does this create a potential problem down the road where I might try to access /xxx_opcache.php and my nginx rewrite rules for the forum catch it and redirect it to the forum?

    I've actually never worked with a server where I intended to use it as the backend to multiple domains, always used dedicated boxes that served only one domain and we never added additional vhost configs, so this idea of setting hostname by default as a subdomain rather than the actual domain just is a bit foreign...
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,488
    12,130
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,671
    Local Time:
    6:03 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    if you don't want to use beta.somedomain.com as the hostname for server, just edit it's server_name value in default server hostname at /usr/local/nginx/conf/conf.d/virtual.conf (command shortcut via SSH = vhostconf) to the desired hostname for the server. Getting started guide summary at very bottom of page sums it up
     
  5. jeffwidman

    jeffwidman Active Member

    152
    27
    28
    Dec 3, 2014
    Ratings:
    +51
    Local Time:
    1:03 PM
    After playing with this, it's clear to me that the best thing is to have the default server hostname *not* on teh root domain, but instead on a subdomain. That way it's easy to create a DNS A record for the subdomain to easily access admin panels without worrying about nginx rewrite rules locking me out of admin panels or forcing me to remember the darn IP address.
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,488
    12,130
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,671
    Local Time:
    6:03 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yeah that's what Getting Started guide suggests hostname.domain.com where hostname = subdomain
     
  7. jeffwidman

    jeffwidman Active Member

    152
    27
    28
    Dec 3, 2014
    Ratings:
    +51
    Local Time:
    1:03 PM
    Actually, the way it's currently worded seems less of a recommendation and more of a "if your host gives you a subdomain for a hostname, here's how to handle this"...

    Perhaps add a simple note like:

    If your host gives you the option of selecting a hostname for your server, it's probably better to use a subdomain like "cloud1.domain.com", not "domain.com". Then you can add the actual domain.com as an Nginx vhost (server block) entry using the Centminmod menu option.

    The problem with using a hostname like "domain.com" is if you ever want to add some user-facing redirects, you'll have to be careful they don't accidentally prevent you from navigating to server admin settings files such as "domain.com/opcache.php". Much better to split the admin-facing file paths onto a separate subdomain resulting in paths like "cloud1.domain.com/opcache.php"

    I know a quick note like this would have helped me.