Difference between revisions of "WebServer - Name-based Virtual Host Support"

From The TinkerNet Wiki
Jump to navigation Jump to search
Line 7: Line 7:
 
*<code>$wgServer = "http://wiki.tinkernow.net";</code>
 
*<code>$wgServer = "http://wiki.tinkernow.net";</code>
  
Then add this to <code>/etc/apache2/apache2.conf</code>
 
  
 
<big>'''NOTE:''' It is probably smarter to put the <code>VirtualHost</code> sections in separate files in the <code>/etc/apache2/sites-available/</code> folder, then make symbolic links to them in <code>/etc/apache2/sites-enabled</code> This will simplify maintenance down the road...</big>
 
<big>'''NOTE:''' It is probably smarter to put the <code>VirtualHost</code> sections in separate files in the <code>/etc/apache2/sites-available/</code> folder, then make symbolic links to them in <code>/etc/apache2/sites-enabled</code> This will simplify maintenance down the road...</big>
<VirtualHost *:80 *:443>
+
 
    # This first-listed virtual host is also the default for *:80
+
But, if you really want to, they can simply be added to <code>/etc/apache2/apache2.conf</code>
    ServerName test.tinkernow.net
 
#    ServerAlias tinkernow.net
 
    DocumentRoot "/var/www/html"
 
</VirtualHost>
 
 
   
 
   
<VirtualHost *:80>
 
    ServerName wiki.tinkernow.net
 
    Redirect permanent / <nowiki>https://wiki.tinkernow.net/</nowiki>
 
    # This line causes http requests to be converted to https...
 
</VirtualHost>
 
 
   
 
   
<VirtualHost _default_:443>
+
A set of files for <code>/etc/apache2/sites-available</code>:
    ServerName wiki.tinkernow.net
+
 
    DocumentRoot "/var/www/wiki"
+
*'''www.foo.bar.conf'''
</VirtualHost>
 
 
<VirtualHost *:80>
 
    ServerName labnotes.tinkernow.net
 
    Redirect permanent / <nowiki>https://labnotes.tinkernow.net/</nowiki>
 
    # This line causes http requests to be converted to https...
 
</VirtualHost>
 
 
<VirtualHost _default_:443>
 
    ServerName labnotes.tinkernow.net
 
    DocumentRoot "/var/www/labnotes"
 
</VirtualHost>
 
 
<VirtualHost *:80>
 
    ServerName blog.tinkernow.net
 
    Redirect permanent / <nowiki>https://blog.tinkernow.net/</nowiki>
 
    # This line causes http requests to be converted to https...
 
</VirtualHost>
 
 
<VirtualHost _default_:443>
 
    ServerName blog.tinkernow.net
 
    DocumentRoot "/var/www/WP"
 
</VirtualHost>
 
 
A set of files for /etc/apache2/sites-available:
 
  
* www.foo.bar.conf
 
 
  #########################
 
  #########################
 
  # WWW.foo.bar          #
 
  # WWW.foo.bar          #
Line 75: Line 39:
 
  </VirtualHost>
 
  </VirtualHost>
  
* wiki.foo.bar.conf  
+
*'''wiki.foo.bar.conf'''
 +
 
 
  #########################
 
  #########################
 
  # Wiki.foo.bar          #
 
  # Wiki.foo.bar          #
Line 93: Line 58:
 
  </VirtualHost>
 
  </VirtualHost>
  
* proxy.foo.bar.conf  
+
*'''proxy.foo.bar.conf'''
 +
 
 
  ##################################
 
  ##################################
 
  # Proxy for T110.foo.CA    #
 
  # Proxy for T110.foo.CA    #

Revision as of 15:53, 28 June 2020

This page was created while splitting my original webserver from a single name to 3 names to make access easier. I moved the wikis to their own subdomains. At some point, I really should clean this page up to make it clearer...

(i.e.: moving it from test.tinkernow.net/wiki to wiki.tinkernow.net)
sudo vim /var/www/LocalSettings.php


NOTE: It is probably smarter to put the VirtualHost sections in separate files in the /etc/apache2/sites-available/ folder, then make symbolic links to them in /etc/apache2/sites-enabled This will simplify maintenance down the road...

But, if you really want to, they can simply be added to /etc/apache2/apache2.conf


A set of files for /etc/apache2/sites-available:

  • www.foo.bar.conf
#########################
# WWW.foo.bar           #
#########################

<VirtualHost *:80>
    ServerName foo.bar
    Redirect permanent / https://www.foo.bar/
</VirtualHost>

<VirtualHost *:80>
    ServerName www.foo.bar
    Redirect permanent / https://www.foo.bar/
</VirtualHost>

<VirtualHost _default_:443>
    ServerName www.foo.bar
    DocumentRoot "/var/www/html"
    SSLCertificateFile /etc/letsencrypt/live/www.foo.bar/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.foo.bar/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
  • wiki.foo.bar.conf
#########################
# Wiki.foo.bar          #
#########################

<VirtualHost *:80>
    ServerName wiki.foo.bar
    Redirect permanent / https://wiki.foo.bar/
</VirtualHost>

<VirtualHost _default_:443>
    ServerName wiki.foo.bar
    DocumentRoot "/var/www/wiki"
    SSLCertificateFile /etc/letsencrypt/live/wiki.foo.bar/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/wiki.foo.bar/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
  • proxy.foo.bar.conf
##################################
# Proxy for T110.foo.CA    #
##################################

<VirtualHost *:80>
    ServerName proxy.foo.bar
    Redirect permanent / https://proxy.foo.bar/
</VirtualHost>

<VirtualHost _default_:443>
    ServerName proxy.foo.bar
    ProxyRequests on
    SSLEngine On
    SSLProxyEngine On
    ProxyPreserveHost On

    # Redirect WSS traffic (Needed if this is a proxy for ESXi)
    ProxyPass /ticket/ wss://proxy.foo.bar/ticket/
    ProxyPassReverse /ticket/ wss://proxy.foo.bar/ticket/

    # Redirect HTTPS traffic
    ProxyPass / https://proxy.foo.bar/
    ProxyPassReverse / https://proxy.foo.bar/

    SSLCertificateFile /etc/letsencrypt/live/proxy.foo.bar/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/proxy.foo.bar/privkey.pem
    <Proxy "*">
        Order allow,deny
        Allow from all
    </Proxy>
        ErrorLog /var/log/apache2/Proxy/proxy_log
        CustomLog /var/log/apache2/Proxy/proxy-access_log combined

</VirtualHost>

and restart Apache:

  • sudo service apache2 restart