LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-13-2016, 02:43 AM   #1
apache1234
LQ Newbie
 
Registered: Apr 2016
Posts: 3

Rep: Reputation: Disabled
Apache - redirect not for local IP


Hello,

I want to redirect any request for http to https. This works fine.

But when the local IP tries to open http-URL it should not be redirected to https - I need this for letsencrypt renewing script.

Is there a way to change the RewriteCond that the locally IP will not be redirected?

Code:
<VirtualHost ...>
.
.
.
.
  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    LogLevel alert rewrite:trace3
  </ifmodule>
.
.
.
.
</VirtualHost>
 
Old 04-13-2016, 03:26 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
I've never had to do anything special with redirections based on IP for letsencrypt.

You don't mention which method of set-up you used but I used the "--webroot" method with .htaccess to do the http>https redirection like this:
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]
</IfModule>
I renew certs with this method:
Code:
letsencrypt certonly --keep-until-expiring --webroot -w /path/to/public_html -d mydomain.com,www.mydomain.com
What problems are you getting?
 
Old 04-13-2016, 03:40 AM   #3
apache1234
LQ Newbie
 
Registered: Apr 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
When I try to renew the certificate the letsencrypt script treis to access to http://mydomain.com/.well-known.... and to http://www.mydomain.com/.well-known....

When now http will be redirected to https the files in the acme-challenge directory can't be found by the script. So I thought it would be the easiest way not to redirect to https when the request comes from the locally IP.
 
Old 04-13-2016, 04:24 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Is there a way to change the RewriteCond that the locally IP will not be redirected?
Yes, add another RewriteCond for the IP you want to exclude:
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REMOTE_ADDR} !^x.x.x.x
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Regards
 
Old 04-13-2016, 09:43 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by apache1234 View Post
When I try to renew the certificate the letsencrypt script treis to access to http://mydomain.com/.well-known.... and to http://www.mydomain.com/.well-known....
You are mistaken. The letsencrypt.org server tries to access the files, not the local script.

Quote:
Originally Posted by apache1234 View Post
When now http will be redirected to https the files in the acme-challenge directory can't be found by the script. So I thought it would be the easiest way not to redirect to https when the request comes from the locally IP.
As per above the verification request does not come from the local IP see below.

From the access_log
Code:
66.133.109.36 - - [13/Apr/2016:15:37:39 +0100] "GET /.well-known/acme-challenge/[REMOVED] HTTP/1.1" 302 299 "-" "Mozilla/5.0 (compatible; Let's Encrypt validation server; +https://www.letsencrypt.org)"
Code:
# nslookup 66.133.109.36
Server:         8.8.8.8
Address:        8.8.8.8#53
Non-authoritative answer:
36.109.133.66.in-addr.arpa      canonical name = ip36-109-133-66.letsencrypt.org.
ip36-109-133-66.letsencrypt.org name = outbound1.letsencrypt.org.
 
Old 04-13-2016, 12:05 PM   #6
apache1234
LQ Newbie
 
Registered: Apr 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Ok thx.

I only assumed this - I did not look into the logfiles.

But the letsencrypt only check this files via http instead of https.

When a new certificate will be requested by the script it only can happen via http but while renewing it also could work via https!
But I believe that the letsencrypt IP addresses will change from time to time.

Then my script must disable the redirecting before renewing or filtering by the browser-agent but this also could be faked very easily. :-(
 
Old 04-14-2016, 11:06 AM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Last couple of posts in this thread http://www.linuxquestions.org/questi...pt-4175577334/ may be helpful.
 
  


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
redirect local traffic to another local IP. ?iptables jschwalbe Linux - Networking 4 07-30-2014 02:38 PM
Redirect traffic from local ip address to another local ip rbaker Linux - Networking 1 03-11-2014 05:03 AM
Redirect local port chenja Linux - Enterprise 1 09-29-2011 01:23 PM
Redirect https apache requests to folder not in apache root bax Linux - Enterprise 4 04-12-2010 01:16 PM
apache redirect to local url nkhetia Linux - Server 1 11-23-2008 03:56 PM

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

All times are GMT -5. The time now is 06:58 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