title: nginx reverse proxy folder 403 error
body: <p>I am running nginx as reverse proxy directly installed on the server. To access different webapps I am using sub folders. Two webapps are running in docker containers (pydio and cops).</p>
  
  <p>For pydio this location commands are working; same one for cops is not working.</p>
  
  <pre><code>   location ^~ /pydio {
      client_max_body_size 20G;
      proxy_connect_timeout 300;
      proxy_send_timeout 300;
      proxy_read_timeout 300;
      send_timeout 300;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://127.0.0.1:82;
      proxy_redirect off;
  }
  </code></pre>
  
  <p>I tried different settings found by searching - none worked.</p>
  
  <p>This is the latest version which results in a 403 error:</p>
  
  <pre><code>   location ^~ /ebooks(.*)$ {
      client_max_body_size 1G;
      proxy_connect_timeout 300;
      proxy_send_timeout 300;
      proxy_read_timeout 300;
      send_timeout 300;
      rewrite ^/ebooks(/.*)$ $1 break;
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $host;
      proxy_pass http://192.168.100.67:83$1/;
      proxy_redirect off;
      autoindex on;
  }
  </code></pre>
  
  <p>And this entry in my error.log:</p>
  
  <blockquote>
    <p>[error] 29235#29235: *1 directory index of "/var/www/ebooks/" is forbidden, client: 87.174.111.111, server: myadress.de, request: "GET /ebooks/ HTTP/1.1", host: "myadress.de"</p>
  </blockquote>
  
  <p>When I hit <em>192.168.100.67:83</em> directly in my browser everything is working fine.</p>
  
  <p>The folder /var/www/ebooks has www-data:www-data and 750 rights and it is linked with the container by the running command: </p>
  
  <p><code>docker run ... -v /var/www/ebooks:/config</code>  ... according to this <a href="https://hub.docker.com/r/lsioarmhf/cops/" rel="nofollow noreferrer">https://hub.docker.com/r/lsioarmhf/cops/</a></p>
  
  <p>Hope I made my problem clear and you will help me. Thanks </p>
  
  <hr>
  
  <p>good an bad news.</p>
  
  <p>After testing a little more I found setting passing the command to docker correctly.</p>
  
  <pre><code>    location ^~ /ebooks {
  
          proxy_connect_timeout 300;
          proxy_send_timeout 300;
          proxy_read_timeout 300;
          send_timeout 300;
          rewrite ^/ebooks(/.*)$ $1 break;
          proxy_set_header X-Real-IP  $remote_addr;
          proxy_set_header Host $host;
          proxy_pass http://127.0.0.1:83$1;
          proxy_redirect off;
  }
  </code></pre>
  
  <p>But cops page is only displayed in a basic way (background color changes but matrix not shown)</p>
  
  <p>This is error log entry:</p>
  
  <blockquote>
    <p>an upstream response is buffered to a temporary file /var/lib/nginx/proxy/1/00/0000000001 while reading upstream, client: 11.114.211.38, server: myadress.de, request:: "GET /ebooks/resources/jQuery/jquery-1.11.1..js?v=1.0.1 HTTP/1.1", upstream: "<a href="http://127.0.0.1:83/resources/jQuery/jquery-1.11.1.min.js" rel="nofollow noreferrer">http://127.0.0.1:83/resources/jQuery/jquery-1.11.1.min.js</a>", host: "myadress.de", referrer: "<a href="https://myadress/ebooks/" rel="nofollow noreferrer">https://myadress/ebooks/</a>"</p>
  </blockquote>
  
  <p>To give you a complete picture. This is nginx config of cops container.</p>
  
  <pre><code>    server {
  
      listen 80 default_server;
  #   listen 443 ssl;
      server_name _;
  #   ssl_certificate /config/keys/cert.crt;
  #   ssl_certificate_key /config/keys/cert.key;
      access_log  /config/log/nginx/access_cops.log;
      error_log /config/log/nginx/error_cops.log;
      root   /var/www/localhost/cops;
      index index.php;
  
      #Useful only for Kobo reader
      location /cops/ {
            rewrite ^/download/(\d+)/(\d+)/.*\.(.*)$ /fetch.php?data=$1&amp;db=$2&amp;type=$3 last;
            rewrite ^/download/(\d+)/.*\.(.*)$ /fetch.php?data=$1&amp;type=$2 last;
            break;
          }
  
          #Can break loading the images - if you don't see anything, comment
          location ~ ^/images.*\.(gif|png|ico|jpg)$ {
                  expires 31d;
          }
          #Can also break loading the images, comment if it happens
          location ~ .(js|css|eot|svg|woff|ttf)$ {
                  expires 31d;
          }
  
      #Not necessarily correct, it depends on distro.
      location ~ \.php$ {
         include /etc/nginx/fastcgi_params;
         fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         fastcgi_pass    127.0.0.1:9000;
      }
  location /books {
        root /;
         internal;
  }
  }
  </code></pre>
  
  <p>Any ideas if I am missing something?</p>