• I want to run multisite on a Ubuntu VPS using LAMP. I want to support subsite domains as well as custom URLs. I am using letsencrypt.

    I couldn’t figure out my virtualhost file, so I let my friend take a swing at it, now it’s jacked up even worse.

    I am having 2 problems.

    1. The url boosterclubnetwork.com (or http://www.boosterclubnetwork.com) loads a completely different site on the same server.

    2. I get a certificate domain mismatch (this seems to be obviously related to the fact that the wrong site is loading).

    <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request’s Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName http://www.boosterclubnetwork.com
    ServerAlias boosterclubnetwork.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/boosterclubnetwork.com/public_html
    <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>

    # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with “a2disconf”.
    #Include conf-available/serve-cgi-bin.conf
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.boosterclubnetwork.com [OR]
    RewriteCond %{SERVER_NAME} =boosterclubnetwork.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>

    <VirtualHost *:80>
    DocumentRoot /var/www/html/boosterclubnetwork.com/public_html
    ServerName http://www.madisonboosters.com
    ServerAlias madisonboosters.com

    # not required Alias /mysite-2.dev “/home/mysite-2”
    <Directory /var/www/html/boosterclubnetwork.com/public_html>
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.madisonboosters.com [OR]
    RewriteCond %{SERVER_NAME} =madisonboosters.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Is that your entire file? You don’t have any directives for handling HTTPS. i.e. <VirtualHost *:443> blocks. But before doing HTTPS, be sure the regular *:80 directives are correctly working. For now, comment out (line starts with #) the rewrite to HTTPS part until you are sure the *:80 directives work.

    Remember to restart Apache after making changes.

    What behavior do you want for each domain (boosterclubnetwork.com and madisonboosters.com)? Right now they both go to the same place. (the DocumentRoot directive) There could be other downstream directives altering the final destinations.

    What multisite setup are you using? subdirectory or subdomain? For complete domain redirects in virtual host, subdirectory is preferable. What folder is your multisite installed in?

    ServerName directive should not include transport protocol (http://)

    I’d also comment out the <directory> blocks for now. You don’t need permissions confusing the issue right now. You can restore them for testing once the basic configuration is working correctly.

    Thread Starter oguruma

    (@oguruma)

    What I am after is being able to use subsites (site1.boosterclubnetwork.com) as well as custom domains (madisonboosters.com).

    What I think is complicating things is I also have certificates via letencrypt/certbot.

    What I thought about was just starting over with a cp of 000-default, but having to handle wildcards for sites.boosterclubnetwork.com and also custom urls is complicating things for me…

    Moderator bcworkz

    (@bcworkz)

    Yes, SSL would complicate things. Focus on simple HTTP requests first, even if you intend to rewrite all to HTTPS. Disclaimer: I’ve not setup both subdomains and multiple domains for a single multisite installation before. With a multisite subdomain configuration, I think you would be forced to rewrite alternate domains to the subdomain.main_domain equivalent for WP to recognize the request. This cannot be done internally, meaning the new address will show in the address bar. Internal rewrites would not show in the address bar.

    I think it would be better to use a subdirectory based multisite and manually (via virtual host and .htaccess directives) handle the various subdomain and alternate domain requests, sending them to the correct subdirectory. These rewrites can be handled internally so the original request remains in the address bar. The drawback is you could not add additional subdomains on the fly because they have to be coded as a rewrite directive. You could still add subdirectory sites on the fly.

    You cannot have wildcard subdomains with LetsEncrypt certificates anyway, so the loss of on the fly subdomain site creation by going to subdirectory configuration shouldn’t be much of a loss. Even though Apache will not alter the address bar with internal rewrites, WP will still redirect to whatever URL it is configured to use in the options table. To have WP also maintain the original request, the WP_SITEURL and WP_HOME constants should be dynamically defined as demonstrated in the Codex.

    Once you have the rewrites working the way you want with HTTP requests, duplicate your <VirtualHost *:80> blocks and change the 80 to 443 in the copies to handle HTTPS requests. In the 443 versions, add in the SSL directives that point to your certificate files.

    Once HTTPS requests are also handled correctly, you can finally add the HTTP to HTTPS rewrite directives in the *:80 blocks.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Virtualhost file for Multisite?’ is closed to new replies.