title: Replace image and javascript absolute paths through proxy_redirect in nginx
body: <p>I have a scenario as follows.</p>
  
  <p>Nginx is being used as a reverse proxy to a apache server listening at port 8080. nginx is running at port 80. There is a wsgi application which is being run by the apache server.</p>
  
  <p>Now, I have added a proxy_pass to the nginx configuration such that whatever requests come to localhost/ (nginx port is the default port 80) they get redirected to localhost:8080.</p>
  
  <p>Here is an excerpt from the nginx conf file:</p>
  
  <pre><code>    server {
         listen 80;
         proxy_set_header X-Real-IP  $remote_addr;
         proxy_set_header X-Forwarded-For $remote_addr;
         proxy_set_header Host $host;
  
         location &lt;app_name&gt; {
                  proxy_pass http://localhost:8080/
                  proxy_redirect http://localhost/ http://localhost:8080/
         }
      }
  </code></pre>
  
  <p>I have added the proxy redirect to take care of any redirects from the apache server so that any request mapping to <code>http://localhost/&lt;something&gt;</code> gets redirected to <code>http://localhost:8080/&lt;something&gt;</code> because the application's resources are going to be available under port 8080. </p>
  
  <p>Now, the problem here is that the wsgi application generates an html where the image and the javascript location paths are absolute paths like /img/image.png and /js/javascript.js. Now, they are part and parcel of the HTML and do not send any redirect with a complete http:// prefix as such therefore, the server tries to locate the images in the localhost/img directory instead of the localhost:8080/img directory.</p>
  
  <p>A dirty workaround for the same could be to have the /img and /js directories also defined as separate "location" in the server config and a proxy_pass specified to them. But then these directories could be more in number and maintaining the same could potentially become a headache. </p>
  
  <p>Is there a cleaner way of doing this?</p>
  
  <p>This is in reference to fixing the issue in graphite <a href="https://bugs.launchpad.net/graphite/+bug/1053219" rel="nofollow">Apache cannot serve graphite-web from URLs other than /</a></p>