title: Flask in production with Caddy and Waitress url_for redirect to localhost
body: <p>I have a Flask server running on a Windows EC2 instance.</p>
  
  <p>I need to have it using <strong>https</strong> protocol, so my setup is like this :</p>
  
  <ul>
  <li>I have a Caddy server</li>
  <li>I use Waitress to run my flask app</li>
  </ul>
  
  <p>Here is my config for Caddy :</p>
  
  <pre><code>example.com:443{
      proxy / 127.0.0.1:8080
      tls me@example.com
  }
  </code></pre>
  
  <p>Everything is working fine excepted that in my <strong>application.py</strong> file, when I do :</p>
  
  <pre><code>return redirect(url_for('test', filename=filename))
  </code></pre>
  
  <p>My web browser redirect me :</p>
  
  <ul>
  <li>from : <strong><a href="https://example.com/" rel="nofollow noreferrer">https://example.com/</a></strong></li>
  <li>to : <strong><a href="http://127.0.0.1/test/my_filename" rel="nofollow noreferrer">http://127.0.0.1/test/my_filename</a></strong></li>
  </ul>
  
  <p>Same result with <code>_external=True</code></p>
  
  <p>But on a template page, for example <strong><a href="https://example.com/test2" rel="nofollow noreferrer">https://example.com/test2</a></strong> rendered using <code>render_template( "test2.html")</code> if I have a link <code>&lt;a href="{{ url_for('index') }}" /&gt;</code> the HTML generated is well : <strong><a href="https://example.com/" rel="nofollow noreferrer">https://example.com/</a></strong></p>
  
  <p>For now I have hard coded my url in application.py but this is not the way that I would like to keep it...</p>