Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to force HTTPS on remote connections and forward all traffic that is not from the 192.168.0 net to https://$host$request_uri but allow access on local connections.

In apache2 I had

Order allow,deny
Allow from 192.168.0
Allow from 127
Deny from all

in the HTTP hosts' config and had to manually change to HTTPS after getting a 403.

Ideally I'd like to add some code to the HTTP section instead of into every server since I setup a lot of subdomains.

I already read the answers from this question and know I can add

return 301 https://$host$request_uri;

But then all traffic is forwarded. I only want to forward REMOTE connections. Mainly to reduce overhead on local connections.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I found a solution using the HttpGeoModule.

By adding (source)

geo $remote {
    default http;
    192.168.0.0/24 0;
    127.0.0.0/8 0;
}

to my http section and adding

if ($remote = $scheme) {
    return 301 https://$host$request_uri;
}

to my default-snippet I achieved what I wanted.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.