Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Apr 07, 2015 3:28 pm 
Offline
Senior Member

Joined: Tue Sep 28, 2010 12:05 pm
Posts: 90
Website: http://www.theatereleven.com
AOL: theatereleven
Location: Santa Monica, CA
I just obtained my SSL certificate, and have modified my virtual host file.

The site works now when I go to https://. But if I type in http:// Apache is not automatically sending me to the https://.

I'm on Debian 7.4. Anyone familiar with making this work? Thanks!!!

_________________
kyler d. boudreau
theatereleven.com


Top
   
PostPosted: Tue Apr 07, 2015 4:02 pm 
Offline
Senior Newbie

Joined: Tue Apr 01, 2014 3:35 pm
Posts: 15
The more common way to do this is via .htaccess by placing the following towards the top of it;
Code:
RewriteEngine On 
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://foobar.com/$1 [R,L]


If for some reason your apache doesn't use the %{HTTPS} bit (I forget but I think there's some cases it won't?), try the following instead
Code:
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://foobar.com/$1 [R,L]


If you have the RewriteEngine On already in your .htaccess, disregard the first line and just make sure you tuck the other two directly under the already existing one (of course replace foobar.com with your domain as well).

It's worth noting though, Apache suggests handling this at the main VHost level; https://wiki.apache.org/httpd/RedirectSSL

If you would like your entire domain to always be https://, make sure you enable HSTS as well (this will need mod_headers enabled in your main apache config);
Code:
Header set Strict-Transport-Security "max-age=31536000"


If you would like to cover all subdomains of your main domain as well;
Code:
Header set Strict-Transport-Security "max-age=31536000;includeSubdomains"


It's worth noting in this case however, in some CGI/FastCGI models that it might not work, so you may have to send this particular header from whatever backend language you're working from.

Might also be worth looking into HPKP if you're really into that extra bit of 'security' for your https:// config.

And of course last but not least, always make sure you do a run of your domain after you set up your https:// through SSL Labs' test just to make sure you don't have any potential issues/weaknesses :P


Top
   
PostPosted: Tue Apr 07, 2015 4:42 pm 
Offline
Senior Member

Joined: Tue Sep 28, 2010 12:05 pm
Posts: 90
Website: http://www.theatereleven.com
AOL: theatereleven
Location: Santa Monica, CA
Thanks so much for the detailed info.

After I posted, I succeeded in getting it to work, but then every other site on my Linode redirected to the one site with HTTPS. I removed all changes, rebooted the Linode, and then none of the sites would even load.

I'm restoring from backup as I type.

So....kind of perplexed on this. I thought I could enable SSL for only one site, while still serving up the other non-SSL sites under the same IP.

If this is possible, I'll try your steps above. Maybe I'm trying something that isn't even doable.

_________________
kyler d. boudreau

theatereleven.com


Top
   
PostPosted: Tue Apr 07, 2015 4:52 pm 
Offline
Senior Newbie

Joined: Tue Apr 01, 2014 3:35 pm
Posts: 15
The first two examples I gave (with the RewriteEngine bit) were designed as noted to go into an .htaccess file, specifically an .htaccess file under the main webroot of whatever domain you want it to affect (eg; /var/www/yourdomain.com/public_html/.htaccess).


Top
   
PostPosted: Tue Apr 07, 2015 6:22 pm 
Offline
Senior Member

Joined: Tue Sep 28, 2010 12:05 pm
Posts: 90
Website: http://www.theatereleven.com
AOL: theatereleven
Location: Santa Monica, CA
I tried your instructions for the htaccess. It worked, however every site on my Linode then redirected to the https site...even though I only edited the .htaccess file on that site. It's so weird. I'm about to just pay Linode to do this. Thought I could do it, but holy crap.

_________________
kyler d. boudreau

theatereleven.com


Top
   
PostPosted: Tue Apr 07, 2015 6:34 pm 
Offline
Senior Newbie

Joined: Tue Apr 01, 2014 3:35 pm
Posts: 15
Yeah that's... really not how it should be happening unless all other 'sites' (eg; domains) are also pointing to that directory in their vhosts configuration.

You didn't do the RewriteRule based one and the RedirectSSL page I linked here; https://wiki.apache.org/httpd/RedirectSSL did you?

You only need one or the other, that URL there will technically do what you're describing, but if you take that route it's not necessary to do the .htaccess model then, but you may run into an issue where all things redirect if you use something that doesn't support SNI properly I believe.

Simple solution is to undo the RedirectSSL changes if you did them and stick with just .htaccess.


Top
   
PostPosted: Wed Apr 08, 2015 8:16 pm 
Offline
Senior Member

Joined: Tue Sep 28, 2010 12:05 pm
Posts: 90
Website: http://www.theatereleven.com
AOL: theatereleven
Location: Santa Monica, CA
I restored my Linode again, and started over with reissuing the cert, etc.

Still cannot get the .htaccess thing to work. Not sure what I'm doing wrong. If I type in the https:// it works without issue. But the redirect doesn't.

Here's my htaccess without the redirect...maybe something is screwed up in it?

Code:

#WFIPBLOCKS - Do not remove this line. Disable Web Caching in Wordfence to remove this data.
Order Deny,Allow
Deny from 77.253.129.181
Deny from 134.249.53.36
#Do not remove this line. Disable Web Caching in Wordfence to remove this data - WFIPBLOCKS
#WFCACHECODE - Do not remove this line. Disable Web Caching in Wordfence to remove this data.
<IfModule mod_deflate.c>
   AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
   <IfModule mod_headers.c>
      Header append Vary User-Agent env=!dont-vary
   </IfModule>
   <IfModule mod_mime.c>
      AddOutputFilter DEFLATE js css htm html xml
   </IfModule>
</IfModule>
<IfModule mod_mime.c>
   AddType text/html .html_gzip
   AddEncoding gzip .html_gzip
   AddType text/xml .xml_gzip
   AddEncoding gzip .xml_gzip
</IfModule>
<IfModule mod_setenvif.c>
   SetEnvIfNoCase Request_URI \.html_gzip$ no-gzip
   SetEnvIfNoCase Request_URI \.xml_gzip$ no-gzip
</IfModule>
<IfModule mod_headers.c>
   Header set Vary "Accept-Encoding, Cookie"
</IfModule>
<IfModule mod_rewrite.c>
   #Prevents garbled chars in cached files if there is no default charset.
   AddDefaultCharset utf-8
   #Cache rules:
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTPS} on
   RewriteRule .* - [E=WRDFNC_HTTPS:_https]
   RewriteCond %{HTTP:Accept-Encoding} gzip
   RewriteRule .* - [E=WRDFNC_ENC:_gzip]
   RewriteCond %{REQUEST_METHOD} !=POST
   RewriteCond %{HTTPS} off
   RewriteCond %{QUERY_STRING} ^(?:\d+=\d+)?$
   RewriteCond %{REQUEST_URI} (?:\/|\.html)$ [NC]
   
   RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher) [NC]
   
   RewriteCond %{REQUEST_URI} \/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)(.*)$
   RewriteCond "%{DOCUMENT_ROOT}/wp-content/wfcache/%{HTTP_HOST}_%1/%2~%3~%4~%5~%6_wfcache%{ENV:WRDFNC_HTTPS}.html%{ENV:WRDFNC_ENC}" -f
   RewriteRule \/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)(.*)$ "/wp-content/wfcache/%{HTTP_HOST}_$1/$2~$3~$4~$5~$6_wfcache%{ENV:WRDFNC_HTTPS}.html%{ENV:WRDFNC_ENC}" [L]
</IfModule>
#Do not remove this line. Disable Web caching in Wordfence to remove this data - WFCACHECODE
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^assets/(.*) /wp-content/themes/roots/assets/$1 [QSA,L]
RewriteRule ^plugins/(.*) /wp-content/plugins/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress



_________________
kyler d. boudreau

theatereleven.com


Top
   
PostPosted: Fri Apr 10, 2015 7:18 pm 
Offline
Senior Member

Joined: Wed Oct 20, 2004 8:55 am
Posts: 120
This is what I did in default-ssl for my SSL virtual host.
Appears to work ok.

Code:
<Virtualhost 70.85.16.162:80>

        ServerName server.kangaby.com

        # Redirect all http trafic to https
        Redirect / https://server.kangaby.com/

</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost 70.85.16.162:443>




Top
   
PostPosted: Wed Jun 17, 2015 10:49 pm 
Offline
Senior Newbie

Joined: Sat Oct 04, 2014 7:31 pm
Posts: 9
kangaby wrote:
This is what I did in default-ssl for my SSL virtual host.
Appears to work ok.

Code:
<Virtualhost 70.85.16.162:80>

        ServerName server.kangaby.com

        # Redirect all http trafic to https
        Redirect / https://server.kangaby.com/

</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost 70.85.16.162:443>




Thanks- I added that to my .conf file (my default-ssl.conf is full of bumpf for whatever reason, so that file is cleaner... but it didn't seem to do anything, nor did it address the permalink issue.


Top
   
PostPosted: Thu Jun 18, 2015 1:45 am 
Offline
Senior Member

Joined: Wed Oct 20, 2004 8:55 am
Posts: 120
Things have changed in Debian Jessie. This needs to go in 000-default.conf now, not in default-ssl and all site configs have to end in .conf (if you are using Jessie)
Remember to reload Apache.
Also
Code:
<IfModule mod_ssl.c>
    <VirtualHost 70.85.16.162:443>
is only a fraction of default-ssl. It was just a place holder to show that the non ssl virtual host part was inserted at the top of default-ssl.


Top
   
PostPosted: Thu Jun 18, 2015 3:42 pm 
Offline
Senior Newbie

Joined: Sat Oct 04, 2014 7:31 pm
Posts: 9
Super! It is now redirecting to https... at least the home page is.

I'm still getting the error on other pages though, due to wordpress permalink issues I believe... when I change them to the default setting in wordpress it is fine, but when I switch the permalink, the pages break...

I feel that my .htaccess isn't working properly, as I think this code should resolve the permalinks:

Code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


Any thoughts on that aspect?


Top
   
PostPosted: Thu Jun 18, 2015 9:17 pm 
Offline
Senior Member

Joined: Wed Oct 20, 2004 8:55 am
Posts: 120
I don't use wordpress, so I can't provide any guidance on the htaccess stuff.
You could try installing WP under the ssl root directory.
As long as the program exists under ssl website, it should work.
You may need to add another redirect like this:

Code:
        # Redirect all http trafic to https
        Redirect / https://server.kangaby.com/
        Redirect /wordpress https://server.kangaby.com/wordpress


Or this may not help at all.


Top
   
PostPosted: Thu Jun 18, 2015 10:32 pm 
Offline
Senior Newbie

Joined: Sat Oct 04, 2014 7:31 pm
Posts: 9
OK thanks for the suggestion, and the help overall- i'll look. I think it has something to do with AllowOveride ALL but not sure which file to put that in.. will tinker around.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group