LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-15-2009, 09:51 PM   #1
auskento
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Help with Apache2 site configuration


I have the following vhost.

Code:
<VirtualHost *:443>
ServerName site.mydomain.com
DocumentRoot "/websites/site.mydomain.com"

        SSLEngine On
        SSLCipherSuite ALL
        SSLCertificateFile /etc/apache2/ssl/server.crt
        SSLCertificateKeyFile /etc/apache2/ssl/server.key

        <Directory />
                Options Indexes FollowSymLinks Indexes MultiViews ExecCGI Includes
                IndexOptions FancyIndexing FoldersFirst NameWidth=*
                HeaderName header.html
                IndexIgnore header.html
                allow from all

                AuthName "Access Authentication"
                AuthUserFile /etc/apache2/usenet.pwd
                AuthType Basic
                Require valid-user

        </Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName site.mydomain.com
DocumentRoot "/websites/site.mydomain.com"

        <Directory />
                Options Indexes FollowSymLinks Indexes MultiViews ExecCGI Includes
                IndexOptions FancyIndexing FoldersFirst NameWidth=*
                HeaderName header.html
                IndexIgnore header.html
                Order deny,allow
                Deny from all
                allow from 192.168.0.0/255.255.255.0
        </Directory>
</VirtualHost>
I am wanting to accomplish the following access to it.

1) If http://site.mydomain.com from internal network, allow
2) If http://site.mydomain.com from external network, forward to https (for SSL and authentication)

What directive should I put in the *:80 site configuration to do this, without breaking internal http access.
(Various services internally will not operate on https)
 
Old 02-16-2009, 02:11 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
take a look at
RewriteCond Directive

http://httpd.apache.org/docs/2.2/rew...ite_guide.html
 
Old 02-16-2009, 02:23 PM   #3
gml_ger
LQ Newbie
 
Registered: Feb 2009
Posts: 1

Rep: Reputation: 1
Code:
<Directory /path/to/your/website>
 RewriteEngine on

  #check if the request is not from the internal network (here 192.168.*.*)
  RewriteCond %{REMOTE_ADDR} !^192\.168

  #check if request is over your http port
  RewriteCond %{SERVER_PORT} =80

  #if both conditions are true tell client to request the page over https
  RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI}

</Directory>
Restart the Apache!

Applications that create a cache of their own circumvent this as far as I can tell. I tried it with KTDMS and if the page was already cached as http it didn't matter if I set the rule and restarted Apache.
It still was delivered as http to external users.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting Apache2 to Wordpress site by default GTBlackwell Linux - Software 1 09-11-2008 02:45 AM
Need help: Apache2 Configuration tombelcher7 Linux - Server 2 02-29-2008 08:32 AM
apache2 vhost site makes default site inaccessible jyamada1 Linux - Server 4 01-17-2007 08:42 PM
apache2 Home practice site comprookie2000 Linux - Networking 3 01-19-2005 04:44 PM
apache2 configuration e1000 Linux - Networking 1 01-27-2004 11:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration