Changes

From SME Server
Jump to navigationJump to search
m
Line 22: Line 22:  
BTW it also effects server-manager at the console, with no way to access server-manager, the only way to regain server-manager at that point was to delete the template and restart.
 
BTW it also effects server-manager at the console, with no way to access server-manager, the only way to regain server-manager at that point was to delete the template and restart.
 
Although it's on the right track it needs a better method as was stated.
 
Although it's on the right track it needs a better method as was stated.
 +
 +
==Alternative Method==
 +
I have done the following and all appears to work OK.
 +
 +
Created a Virtual Domain ''vdomain.com'' in server-manager panel then
 +
db domains setprop vdomain.com Content joomla
 +
db domains setprop vdomain.com WebApp yes
 +
 +
Created a new template fragment
 +
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts
 +
cd /etc/e-smith/templates-custom/etc/httdp/conf/httpd.conf/VirtualHosts
 +
cp /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/20IbayContent 20IbayContent
 +
 +
Now edit and change the file 20IbayContent. Lines marked + have been added
 +
  {
 +
      use esmith::AccountsDB;
 +
      my $accounts = esmith::AccountsDB->open_ro;
 +
 
 +
      use esmith::DomainsDB;
 +
      my $domains = esmith::DomainsDB->open_ro;
 +
 +
      $OUT = "";
 +
 +
      my $ibay = $virtualHostContent;
 +
 +
+    if (( $domains->get_prop($virtualHost, 'WebApp') || 'no') eq 'yes') {
 +
+        my $basedir = "/opt/$ibay";
 +
+        $OUT .= "    DocumentRoot        $basedir\n";
 +
+    }
 +
+    else {
 +
          my $basedir = "/home/e-smith/files/ibays/$ibay";
 +
          my $cgiBin = $accounts->get_prop($ibay, "CgiBin") || "";
 +
 
 +
          $OUT .= "    DocumentRoot        $basedir/html\n";
 +
 
 +
          if ($cgiBin)
 +
          {
 +
              $OUT .= "    ScriptAlias /cgi-bin $basedir/cgi-bin\n";
 +
          }
 +
          else
 +
          {
 +
              $OUT .=
 +
                      "    # To add cgi-bin ScriptAlias for this i-bay, run:\n"
 +
                    . "    #  /sbin/e-smith/db accounts setprop $ibay CgiBin "
 +
                              . "enabled\n"
 +
                    . "    #  /sbin/e-smith/signal-event console-save\n";
 +
          } 
 +
          $OUT .= "    Alias      /files  $basedir/files\n";
 +
+    }
 +
 +
      if (($domains->get_prop($virtualHost, 'SystemPrimaryDomain') || 'no')
 +
          eq 'yes')
 +
      {
 +
          my @ibays = $accounts->ibays;
 +
          foreach my $ibay (@ibays)
 +
          {
 +
              my $key = $ibay->key;
 +
              next if $key eq $virtualHostContent;
 +
              my $basedir = "/home/e-smith/files/ibays/$key";
 +
              my $cgiBin = $ibay->prop("CgiBin") || "";
 +
              my $name = $ibay->prop("Name") || "";
 +
 +
              $OUT .= "\n";
 +
              $OUT .= "    # $key ibay ($name)\n";
 +
              $OUT .= "\n";
 +
 +
              if ($cgiBin)
 +
              {
 +
                  $OUT .= "    ScriptAlias /$key/cgi-bin $basedir/cgi-bin\n";
 +
              }
 +
              else
 +
              {
 +
                  $OUT .=
 +
                      "    # To add cgi-bin ScriptAlias for this i-bay, run:\n"
 +
                      . "    #  /sbin/e-smith/db accounts setprop $key CgiBin "
 +
                                  . "enabled\n"
 +
                      . "    #  /sbin/e-smith/signal-event console-save\n";
 +
              }
 +
 
 +
              $OUT .= "    Alias      /$key/files  $basedir/files\n";
 +
 +
              # Make sure this one is last since it's a prefix of the above
 +
              # aliases. If we put it first, it would get expanded before the
 +
              # other aliases, creating problems.
 +
 +
              $OUT .= "    Alias      /$key        $basedir/html\n";
 +
          }
 +
          $OUT .= "    # No ibays in system\n" unless @ibays;
 +
      }
 +
  }
 +
 +
Expand the template and restart httpd
 +
expand-template /etc/httpd/conf/httpd.conf
 +
sv t httpd-e-smith
 +
 +
Works OK for me. Only tested with a Virtual Domain and joomla as the webapp. Generates a standard VirtualHost entry in httpd.conf, but with just the DocumentRoot changed. The Content db setting of joomla shows up in server-manager, but a modify then ignores it and reverts to setting options for available ibays. Obviously the Content property needs to be set to the directory name under /opt where the web application resides.
 +
 +
I haven't tested it, but I assume if you had no VirtualDomains defined and set the Primary Domain to be redirected you would still get the standard VirtualHost entry created and therefore still have access to server-manager etc. - [[User:Timn|Timn]] 12:54, 15 February 2010 (UTC)
 +
 +
I have also created a file 30DomWebappRedirect in the same folder as above with following content
 +
{
 +
    # vim: ft=perl:
 +
 +
    use esmith::DomainsDB;
 +
    my $domains = esmith::DomainsDB->open_ro;
 +
 +
    $OUT = "";
 +
 +
    if (( $domains->get_prop($virtualHost, 'WebApp') || 'no') eq 'yes') {
 +
 +
        $haveSSL = (exists ${modSSL}{status} and ${modSSL}{status} eq "enabled") ?  'yes' : 'no';
 +
        my $webapp = $virtualHostContent;
 +
        my $webappStatus = ${$webapp}{'status'} || "disabled";
 +
        my $webappAccessType = ${$webapp}{'access'} || "SSL";
 +
        my $webappURL = <nowiki>''</nowiki>;
 +
        if (exists ${$webapp}{'URL'}) {
 +
            my $webappURL = ${$webapp}{'URL'};
 +
        }
 +
 +
        return "    # web application $webapp is disabled in this VirtualHost"
 +
                unless $webappStatus eq 'enabled';
 +
 +
        if (($port eq "80") && ($haveSSL eq 'yes') && ($webappAccessType eq 'SSL'))
 +
        {
 +
            $OUT .= "    RewriteRule ^/$webapp(/.*|\$)    https://%{HTTP_HOST}/\$1 [L,R]\n";
 +
            if (($webappURL || <nowiki>''</nowiki>) ne <nowiki>''</nowiki>) {
 +
                $OUT .= "    RewriteRule ^/$webappURL(/.*|\$)    https://%{HTTP_HOST}/\$1 [L,R]\n";
 +
            }
 +
            $OUT .= "    RewriteRule ^/(/.|\$)            https://%{HTTP_HOST}/\$1 [L,R]\n";
 +
        }
 +
        elsif ($port eq "80") {
 +
            $OUT .= "    RewriteRule ^/$webapp(/.*|\$)    http://%{HTTP_HOST}/\$1 [L,R]\n";
 +
            if (($webappURL || <nowiki>''</nowiki>) ne <nowiki>''</nowiki>) {
 +
                $OUT .= "    RewriteRule ^/$webappURL(/.*|\$)    http://%{HTTP_HOST}/\$1 [L,R]\n";
 +
            }
 +
        }
 +
        elsif ($port eq "443") {
 +
            $OUT .= "    RewriteRule ^/$webapp(/.*|\$)    https://%{HTTP_HOST}/\$1 [L,R]\n";
 +
            if (($webappURL || <nowiki>''</nowiki>) ne <nowiki>''</nowiki>) {
 +
                $OUT .= "    RewriteRule ^/$webappURL(/.*|\$)    https://%{HTTP_HOST}/\$1 [L,R]\n";
 +
            }
 +
        }
 +
    }
 +
}
 +
Now any reference to the original web application alias will be redirected to root. It also catches any alternative URL set.
 +
 +
Also you can enforce SSL by
 +
config setprop webapp access SSL
 +
or not
 +
config setprop webapp access public
 +
 +
Again, works for me with joomla. [[User:Timn|Timn]] 15:02, 17 February 2010 (UTC)

Navigation menu