Changes

Jump to navigation Jump to search
1,729 bytes added ,  04:48, 16 April 2018
no edit summary
Line 1: Line 1:  +
{{Note box|this is the default behaviour for SME since e-smith-ibays-2.4.0-10 has been released}}
 +
 
== https forced redirection using custom template ==
 
== https forced redirection using custom template ==
   Line 9: Line 11:  
====Problem:====
 
====Problem:====
   −
You want to force https access to an ibay whenever you access it using http
+
You want to force https access to an ibay, a Web directory or all web contents of your server, whenever you access it using http
      
====Solution:====
 
====Solution:====
   −
Create a custom template that forces the redirection from http to https
+
Create a custom template that forces the redirection from http to https. This is a similar method to that used to force webmail to https
 
  −
This is a similar method to that used to force webmail to https
  −
      
====Information:====
 
====Information:====
Line 40: Line 38:  
  nano 60redir-ibayname1
 
  nano 60redir-ibayname1
   −
Paste or type the following code including the brackets, replacing '''all ibayname''' with the name of your ibay
+
Paste or type the following code including the brackets, replacing each occurrence of '''ibayname''' with the name of your ibay
    
  {
 
  {
Line 54: Line 52:  
  }
 
  }
 
  }
 
  }
 +
 +
Save the file & exit by Ctrl+x, then issue the following command
   −
Save the file & exit by Ctrl+x
+
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
 +
 
 +
sv t /service/httpd-e-smith/
 +
 
 +
* This is an alternative if the solution above doesn't work.
 +
 
 +
{
 +
if ($port ne "443")
 +
{
 +
$OUT .= <<'HERE';
 +
# Redirect transmission Address to Secure Address
 +
RewriteEngine On
 +
RewriteCond %{HTTPS} off
 +
RewriteRule /'''ibayname''' <nowiki>https://%{HTTP_HOST}:443/</nowiki>'''ibayname'''
 +
## End Of Redirect
 +
HERE
 +
}
 +
}
 +
 
 +
Save the file & exit by Ctrl+x, then issue the following command
    
  /sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
 
  /sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
   −
  /etc/init.d/httpd restart
+
  sv t /service/httpd-e-smith/
   −
     −
If you wish to force https access to other ibays then make additional template fragments with a different filename that contain the same code except with the ibay name changed to suit
+
* If you wish to force https access to other ibays then make additional template fragments with a different filename that contain the same code except with the ibay name changed to suit
    
eg
 
eg
    
61redir-ibayname2
 
61redir-ibayname2
 +
 +
* Alternatively if you want to force all http trafics to https, you can make a general rule like this.
 +
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts
 +
cd /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts
 +
nano 60all-httptohttps
 +
 +
{
 +
if ($port ne "443")
 +
{
 +
$OUT .= <<'HERE';
 +
# Redirect transmission Address to Secure Address
 +
RewriteEngine On
 +
RewriteCond %{HTTPS} off
 +
RewriteRule (.*) <nowiki>https://%{HTTP_HOST}%{REQUEST_URI}</nowiki>
 +
## End Of Redirect
 +
HERE
 +
}
 +
}
 +
 +
Save the file & exit by Ctrl+x, then issue the following command
 +
 +
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
 +
 +
sv t /service/httpd-e-smith/
 +
    
Warning: If you receive errors when you expand the template that refer to not finding HERE before EOF, then make sure you have no spaces before or after the HERE entry in the code
 
Warning: If you receive errors when you expand the template that refer to not finding HERE before EOF, then make sure you have no spaces before or after the HERE entry in the code
Line 93: Line 136:     
This modifies the original code slightly & needs only one 60redir-ibay custom fragment  
 
This modifies the original code slightly & needs only one 60redir-ibay custom fragment  
 +
 +
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts
 +
 +
cd /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts
 +
 +
nano -w 60redir-ibay
 +
 +
Then paste this
    
  {
 
  {
Line 98: Line 149:  
     my $adb = esmith::AccountsDB->open_ro();
 
     my $adb = esmith::AccountsDB->open_ro();
 
     $OUT = "";
 
     $OUT = "";
 
+
 
     foreach my $ibay ($adb->ibays)
 
     foreach my $ibay ($adb->ibays)
 
     {
 
     {
Line 119: Line 170:  
  }
 
  }
   −
Follow the procedure from the earlier part of this Howto & then issue this db command
     −
  db accounts setprop ibayname HTTPSredir on
+
Save the file & exit by Ctrl+x, then issue the following command
 +
 
 +
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
 +
 
 +
sv t /service/httpd-e-smith/
 +
 
 +
then issue this db command, you have to change '''ibayname''' to the actual name of your ibay
 +
  db accounts setprop '''ibayname''' HTTPSredir on
    
==Alternative methods ==  
 
==Alternative methods ==  
Super Admin, Wiki & Docs Team, Bureaucrats, Interface administrators, Administrators
3,250

edits

Navigation menu