title: nginx to flask doesn't preserve path
body: <p>With Nginx I am forwarding request to flask app to serve some cert files.</p>
  <p>custom_list.html</p>
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html lang=&quot;en&quot;&gt;
      &lt;head&gt;
          &lt;meta charset=&quot;UTF-8&quot;&gt;
          &lt;title&gt;Files&lt;/title&gt;
          &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css&quot;
                integrity=&quot;sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7&quot; crossorigin=&quot;anonymous&quot;&gt;
  
          &lt;style type=&quot;text/css&quot;&gt;
              table {
                  font-family: arial, sans-serif;
                  border-collapse: collapse;
                  width: 100%;
              }
  
              td, th {
                  border: 1px solid #dddddd;
                  text-align: left;
                  padding: 8px;
              }
  
              tr:nth-child(even) {
                  background-color: #dddddd;
              }
          &lt;/style&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;div class=&quot;container&quot;&gt;
  
          &lt;div class=&quot;row&quot;&gt;
              &lt;div align=&quot;center&quot; class=&quot;col-lg-12&quot;&gt;
                  &lt;h2 class=&quot;page-header&quot;&gt;Files&lt;/h2&gt;
              &lt;/div&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Name&lt;/th&gt;
                      &lt;th&gt;Expiry&lt;/th&gt;
                  &lt;/tr&gt;
  
                  {% for file in files %}
                  &lt;tr&gt;
                      &lt;td&gt;&lt;a href=&quot; {{ url_for('send_image',filename=file.name) }}&quot;&gt;{{ file.name }}&lt;/a&gt;&lt;/td&gt;
                      &lt;td&gt;{{ file.exp }}&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  {% endfor %}
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      {% if error %}
      &lt;div class=&quot;alert&quot;&gt;
          &lt;strong&gt;Error : &lt;/strong&gt; {{ error }}
      &lt;/div&gt;
      {% endif %}
      &lt;/div&gt;
      &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js&quot;
              integrity=&quot;sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS&quot;
              crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  <p>app.py</p>
  <pre><code>    import datetime
      import os
      import os.path as op
      from OpenSSL import crypto as c
      from flask import Flask, render_template, send_from_directory
  
      app = Flask(__name__, static_folder='')
  
  
      @app.route('/', methods=['Get', 'POST'])
      def index():
          files_details = []
          for base, dirs, files in os.walk('files'):
              for file in files:
                  if file.split(&quot;.&quot;)[-1] == &quot;crt&quot; or file.split(&quot;.&quot;)[-1] == &quot;base&quot;:
                      f = open(&quot;files/base.crt&quot;, &quot;r&quot;)
                      print()
                      cert = c.load_certificate(c.FILETYPE_PEM, f.read())
                      exp = datetime.datetime.strptime(cert.get_notAfter().decode(&quot;utf-8&quot;), &quot;%Y%m%d%H%M%SZ&quot;).strftime(
                          &quot;%Y-%m-%d-%H:%M:%S&quot;)
                      files_details.append({&quot;name&quot;: file,
                                            &quot;exp&quot;: exp})
                  else:
                      files_details.append({&quot;name&quot;: file, &quot;exp&quot;: &quot;N/A&quot;})
  
              for fil in files_details:
                  print(fil.get('name'))
  
              return render_template(&quot;custom_list.html&quot;, files=files_details, test=&quot;test&quot;)
  
  
      @app.route('/flask/files/&lt;filename&gt;')
      def send_image(filename):
          return send_from_directory(f&quot;files/&quot;, filename)
  
  
      if __name__ == '__main__':
          app.run(host='0.0.0.0', port=5000, debug=True)
  </code></pre>
  <p>Following is Nginx Config</p>
  <pre><code>    upstream base-cert {
          server base-cert:5000;
      }
  
      server {
          listen         80 default_server;
          server_name    localhost;
          keepalive_timeout 70;
          gzip on;
          gzip_disable &quot;msie6&quot;;
          gzip_vary on;
          gzip_proxied any;
          gzip_comp_level 6;
          gzip_buffers 16 8k;
          gzip_http_version 1.1;
          gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript;
  
          ....
  
          location /utility/base-cert/ {
              proxy_pass http://base-cert;
          }
      }
  
  </code></pre>
  <p>I am can access <code>https://example.com/utility/base-cert</code>. But when I click on some file to download it, path is changes in a browser to <code>https://example.com/files/ca.crt</code>.</p>
  <p>It should be <code>https://example.com/utility/base-cert/files/ca.crt</code></p>
  <p>What I am missing here ?</p>