logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Force users to SSL HTTPS only, not working. Correct method?
Author
mewbie



Joined: 23 May 2009
Posts: 25

PostPosted: Thu 04 Jun '09 7:09    Post subject: Force users to SSL HTTPS only, not working. Correct method? Reply with quote

using: Linux Debian / apache2-mpm-prefork 2.2.9-10+lenny2
Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch mod_python/3.3.1 Python/2.5.2 mod_ssl/2.2.9 OpenSSL/0.9.8g mod_perl/2.0.4 Perl/v5.10.0 Server at ********* Port 80

I've been trying for days to get redirect/force users to 'https' SSL only without success. For example a user typed: http://whatever.com they will be redirected to: https:/whatever.com

I've read and done a variety of things (note I remove what I have done before trying next method):

1.) add to apache2.conf this line:
Redirect permanent / https://my.url.com/

Produces Loop error "redirecting the request for this address in a way that will never complete."

============
2.) Create a .htaccess and put it in webroot (/var/www/.htaccess) (I presently don't use any .htaccess files):
pico /var/www/.htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

chmod 644 /var/www/.htaccess
/etc/init.d/apache2 reload

Produces this error: "Internal Server Error <The server encountered an internal error or misconfiguration and was unable to complete your request....."

============also tried this code in .htaccess and produced same error:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://myurl.com/$1 [R,L]

============
3.) Read to add this line to apache2.conf:
LoadModule rewrite_module modules/mod_rewrite.so

Produced this error: Cannot load /etc/apache2/modules/mod_rewrite.so into server: /etc/apache2/modules/mod_rewrite.so: cannot open shared object file: No such file or directory failed!

As suspected as I can't find (grep) in 'any' of the files the "LoadModule" line, period.

The only thing I could find that sounds related was this here:
/etc/apache2/mods-available/rewrite.load
so seems this module isn't even loaded as it's not in the /mods-enabled/ directory.

============
4.) Tried this too:

< VirtualHost *:80 >, add/uncomment such that the following lines read as required:
RewriteEngine on
RewriteRule ^/(protected.*) https://website.com/$1

So I:

pico /etc/apache2/sites-available/default
Was this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/

Changed to:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
RewriteEngine on
RewriteRule ^/(.*) https://myurl.com/$1

DocumentRoot /var/www/

/etc/init.d/apache2 reload
Syntax error on line 3 of /etc/apache2/sites-enabled/000-default:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration failed!

Please if anyone could help solve this that would be great!
Thank you for your time Very Happy
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 04 Jun '09 11:48    Post subject: Reply with quote

A short example for a folder.

Code:

RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule (.*)       https://www.example.com/protected/$1      [R,L]



----- edit ---

it also seems that your rewrite module is not loaded.
You need to create a symlink from
/etc/apache2/mods-available/rewrite.load
to
/etc/apache2/mods-enabled/rewrite.load

also you need to enable the rewrite with

Code:

a2enmod rewrite
Back to top
mewbie



Joined: 23 May 2009
Posts: 25

PostPosted: Fri 05 Jun '09 6:35    Post subject: Yay! Thank you! Reply with quote

James Blond Very Happy thank you! Its purrrfect. And working even without the symlink, I skipped that part to test first. And no .htaccess!

One thing I do notice is the prompt window for name/password comes up before it redirects me. I enter info, URL changes to https and page loads.

So is the name/pass being sent via SSL?

btw, off subject, fun read, take a look here if you haven't already astalavista.com , got hacked.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Fri 05 Jun '09 15:20    Post subject: Reply with quote

I guess it is over SSL, but not for sure.
If you have different log files (vhost and ssl vhost youcan check for the 401 "error" and see in which of the log files it is.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 06 Jun '09 2:15    Post subject: Reply with quote

So is the name/pass being sent via SSL?

Good question,

Where is Authentication set up? At both ends http/https (as would be if set up in a .htaccess file e.g. "a shared config")? If so then one could safely assume that no, it is not being sent encrypted but being sent plain text and then redirected after passing auth test.

James has the way to check .. my guess is you will find it in the regular access log, not the ssl one. I will be happy if proven wrong.
Back to top
mewbie



Joined: 23 May 2009
Posts: 25

PostPosted: Sun 07 Jun '09 10:37    Post subject: Reply with quote

Wish I could give a conclusive answer but I can't find a 'ssl log' file.
I have only found: /var/log/apache2/access.log & error.log

I don't think either have any reference to it.

Error log has some errors, but I believe it to be for AjaxTerm I'm setting up:
[Sun Jun 07 06:25:02 2009] [notice] mod_python: Creating 8 session mutexes based on 50 max processes and 0 max threads.
[Sun Jun 07 06:25:02 2009] [notice] mod_python: using mutex_directory /tmp
[Sun Jun 07 06:25:03 2009] [notice] Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch mod_python/3.3.1 Python/2.5.2 mod_ssl/2.2.9 OpenSSL/0.9.8g mod_perl/2.0.4 Perl/v5.10.0 configured -- resuming normal operations
[Sun Jun 07 06:25:03 2009] [error] proxy: ap_get_scoreboard_lb(1) failed in child 24698 for worker proxy:reverse
[Sun Jun 07 06:25:03 2009] [error] proxy: ap_get_scoreboard_lb(0) failed in child 24698 for worker http://localhost:8022/


Quote:
Where is Authentication set up? At both ends http/https (as would be if set up in a .htaccess file e.g. "a shared config")?

I did only as you posted.. adding those lines to: pico /etc/apache2/sites-available/default

Are there further steps I should take to ensure name/passwords are passed via SSL? I set it up for entire site, not just a folder:

Was this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/

Changed to:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
RewriteEngine on
RewriteRule ^/(.*) https://mysite.com/$1

DocumentRoot /var/www/


Thank you again

PS: glsmith I'm still waiting on your part 2 mod_security Very Happy
Back to top


Reply to topic   Topic: Force users to SSL HTTPS only, not working. Correct method? View previous topic :: View next topic
Post new topic   Forum Index -> Apache