Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 0 down vote accepted

I found a solution using the HttpGeoModule.

By adding (source)

geo $remote {
    default http; 0; 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


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.