<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Krešo Kunjas on Medium]]></title>
        <description><![CDATA[Stories by Krešo Kunjas on Medium]]></description>
        <link>https://medium.com/@kkunjas?source=rss-20b97c81aa82------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XuDvxe9fJyF8NG1n.jpg</url>
            <title>Stories by Krešo Kunjas on Medium</title>
            <link>https://medium.com/@kkunjas?source=rss-20b97c81aa82------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:39:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kkunjas/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Authentication behind reverse proxy]]></title>
            <link>https://medium.com/trikoder/auth-behind-reverse-proxy-3b3f81897cb7?source=rss-20b97c81aa82------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b3f81897cb7</guid>
            <category><![CDATA[trikoder]]></category>
            <category><![CDATA[auth]]></category>
            <category><![CDATA[http-auth]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[apache]]></category>
            <dc:creator><![CDATA[Krešo Kunjas]]></dc:creator>
            <pubDate>Fri, 21 Jul 2017 09:12:00 GMT</pubDate>
            <atom:updated>2019-01-09T10:32:41.637Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UYWDydbkXOYAdes07Ag1Gw.jpeg" /></figure><h4>Usually you have a simple web server that needs to have basic HTTP auth, but you also want to allow some IPs or IP range to access this server without authentication (office VPN, office fixed external IP, etc.).</h4><p>This is easily done by adding some directives to your virtual host config (example is for Apache2):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72c4e3ac2288e02a2bfbfa525b8c033b/href">https://medium.com/media/72c4e3ac2288e02a2bfbfa525b8c033b/href</a></iframe><p>And this works just fine. If you came from one of two stated IPs there is no authentication dialog and you can access the server without any restrictions.</p><p><strong>Problem with proxies</strong></p><p>But if you have a somewhat more complex situation, this won’t work as is.</p><p>For example, if your server is behind a reverse proxy, you will again be greeted with the basic auth dialog. Why?</p><p>Because the IP that Apache gets now isn’t your IP but proxy’s IP. As your IPs aren’t matched anymore, you get the auth dialog requiring username and password.</p><p><strong>So how to fix this?</strong></p><p>Usually, most of the proxies forward original IP to servers behind them. So we just need to check that header and allow access if this is one of our allowed IPs.</p><p>Apache2 doesn’t have a directive to check the header directly, but we can use a simple workaround. ;)</p><p>Here is our new config:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cc7622eaaa9ad5306045dac0371598e/href">https://medium.com/media/8cc7622eaaa9ad5306045dac0371598e/href</a></iframe><p>If you are using Apache version 2.4 or higher, here is a slightly different config:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13b06e99578d0dbaa6184a0798ff09fa/href">https://medium.com/media/13b06e99578d0dbaa6184a0798ff09fa/href</a></iframe><p>So we check if header X-Forwarded-For. (This is a standard HTTP header that most proxies set by default. If not, you need to alter your proxy config to set this header.) If it’s content matches our IP (matching uses regex so we need to escape dots), we set environment variable env_allow_1.</p><p>Then “Allow from” directive checks if this variable is set and allows access.</p><p>If you are using <strong>nginx</strong>, the procedure is similar. Instead of checking headers sent from the proxy, you use real_ip module (on Debian/Ubuntu it’s compiled in by default).</p><p>This module adjusts client_ip to one set by allowed proxy and header specified. You need to set from which proxy IP this is accepted, and which header to look at. Here is an example nginx config:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10f5494aab89b4402f4525b1b26c4d81/href">https://medium.com/media/10f5494aab89b4402f4525b1b26c4d81/href</a></iframe><p>First we setup real_ip module by allowing client_ip to be set only by proxy with IP 10.20.30.40 and using header X-Forwarded-For.</p><p>This is it, with just some minor changes our auth works as before.</p><p><strong>Thank you for reading. Please comment, like or share it with your friends and we hope to see you soon.</strong></p><p><strong>Would you like to join us? Check out the open positions at our </strong><a href="http://www.trikoder.hr/karijera/"><strong>Careers page</strong></a><strong>.</strong></p><p><a href="http://www.trikoder.net/"><strong>Trikoder </strong></a><strong>provides high-class software development. We analyse, strategize, design, code and develop complex web systems.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b3f81897cb7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trikoder/auth-behind-reverse-proxy-3b3f81897cb7">Authentication behind reverse proxy</a> was originally published in <a href="https://medium.com/trikoder">Trikoder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>