• Resolved Bullrunner

    (@bullrunner)


    Hi, can anyone please help with some info on creating an Apache virtual hosts file for a multisite installation?

    The subdomain sites are stored in /wp-content/uploads/sites/2, /wp-content/uploads/sites/3, /wp-content/uploads/sites/4, etc.

    My standard virtual hosts file for a single site installation would normally be:

    <VirtualHost *:80>
    	ServerAdmin [email protected]
    	ServerName example.com
    	ServerAlias www.example.com
    	DocumentRoot /srv/www/example.com/public_html/
    	ErrorLog /srv/www/example.com/logs/error.log
    	CustomLog /srv/www/example.com/logs/access.log combined
    	Options +ExecCGI
    	AddHandler cgi-script .cgi .pl
    <Directory /srv/www/example.com/public_html/>
    AllowOverride all
    Options +FollowSymLinks
    Require all granted
    </Directory>
    </VirtualHost>

    Do I therefore need to create a vhosts file for each individual subdomain like this:

    <VirtualHost *:80>
    	ServerAdmin [email protected]
    	ServerName subdomain.example.com
    	ServerAlias subdomain.example.com
    	DocumentRoot /srv/www/example.com/public_html/wp-content/uploads/sites/2
    	ErrorLog /srv/www/example.com/wp-content/uploads/sites/2/logs/error.log
    	CustomLog /srv/www/example.com/wp-content/uploads/sites/2/logs/access.log combined
    	Options +ExecCGI
    	AddHandler cgi-script .cgi .pl
    <Directory /srv/www/example.com/public_html/wp-content/uploads/sites/2>
    AllowOverride all
    Options +FollowSymLinks
    Require all granted
    </Directory>
    </VirtualHost>

    I think I need separate vhosts files for Letsencrypt certs but I don’t know if I need the DocumentRoot, ErrorLog, CustomLog and Directory to link to the folder in which the subdomain site is installed or just use the top level folder as in the vhosts for the main domain.

    Many thanks

    DBR

    • This topic was modified 5 years, 5 months ago by Bullrunner.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Bullrunner

    (@bullrunner)

    Er…I think I’m an idiot….

    The subdomain folders only contain images for the network sites. So all vhosts should just use the same config as the main site but with the subdomain URLs:

    <VirtualHost *:80>
    	ServerAdmin [email protected]
    	ServerName subdomain.example.com
    	ServerAlias subdomain.example.com
    	DocumentRoot /srv/www/example.com/public_html/
    	ErrorLog /srv/www/example.com/logs/error.log
    	CustomLog /srv/www/example.com/logs/access.log combined
    	Options +ExecCGI
    	AddHandler cgi-script .cgi .pl
    <Directory /srv/www/example.com/public_html/>
    AllowOverride all
    Options +FollowSymLinks
    Require all granted
    </Directory>
    </VirtualHost>

    Is that right?

    If your dns is on a single ip address (for the main domain and subdomain).
    https://httpd.apache.org/docs/2.4/vhosts/examples.html
    For (SSL) load balancing or reverse proxy https://httpd.apache.org/docs/2.2/mod/core.html#servername mod_ssl version with SNI support (standard in Apache releases since 2.2.12).
    Jolly * (ServerAlias) https://httpd.apache.org/docs/2.2/vhosts/name-based.html#using

    Listen 172.20.30.40:80
    Listen 172.20.30.40:443
    <VirtualHost 172.20.30.40:80>
        DocumentRoot "/www/example1-80"
        ServerName https://www.example.com:80
    </VirtualHost>
    
    <VirtualHost 172.20.30.40:443>
        DocumentRoot "/www/example1-443"
        ServerName https://www.example.com:443
    </VirtualHost>

    request the certificate from the domain https://www.example.com and add *. for any subdomain.

    Thread Starter Bullrunner

    (@bullrunner)

    Thanks for the info, @autotutorial, but my question was just about folder links in vhosts for multisite installations.

    I’m looking for confirmation that I don’t need to create DocumentRoot, ErrorLog, CustomLog and Directory links to the separate folders in the vhosts for the subdomains in a multisite installation.

    Given that I can see that the folders for each of the subdomain/sub-directory sites just contains images, I’m pretty sure that I don’t need to create different folder links and the top level domain link is fine to use in all the vhosts but it’s always helpful to check.

    Thanks again.

    • This reply was modified 5 years, 5 months ago by Bullrunner.
    • This reply was modified 5 years, 5 months ago by Bullrunner.
    Thread Starter Bullrunner

    (@bullrunner)

    I’ve found the answer to my question:

    A domain-based network maps different domain names to the same directory in the server’s file system where WordPress is installed. You can do this in various ways, for example:

    • by configuring wildcard subdomains
    • by configuring virtual hosts, specifying the same document root for each
    • by creating addon domains or subdomains in cPanel or in a similar web hosting control panel

    So, yes, I just need to use the same document root folder in my vhosts files for each subdomain.

    https://www.ads-software.com/support/article/before-you-create-a-network/#domain-based

    • This reply was modified 5 years, 5 months ago by Bullrunner.

    wordpress does nothing more than join the main or secondary site you set in your dns
    If you need different error_log or access log for different domains, the choice is yours.

    Thread Starter Bullrunner

    (@bullrunner)

    Perfect. Thanks for the additional info. I think I’ll stick to just one log file as the sites are all part of the same client network.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Apache Virtual Hosts file for WP Multisite’ is closed to new replies.