1

I have a website build with Play! Framework that I show with NGinx using ssl.

Everything works fine but I'd like to implement a file upload limit based on url :

  • If the user upload a file to */pages/** (/pages/ or /page/{id}/edit), I will limit the size to 10Mo (it will be zip archive)
  • If the user upload a file to */images/** (/images/ or /images/{id}/edit), I will limit the size to 2Mo (it will be only images)

Here's where I'm stuck :

  1. I saw the client_max_body_size directive, that is exactly what I want, but do I have to specify for every location {}, the proxy_* configuration ?
  2. I have a specific message to display if the user reach the quota allowed, in my app (located at /errors/413). If I go directly using my browser, it works. But using the configuration below, I've got a "504 Gateway Time-out". Why?

Here's my config file :

server {
    listen    443;

    server_name www.mywebsite.com;

    access_log  /var/log/nginx/mywebsite_access.log;
    error_log   /var/log/nginx/mywebsite_error.log;

    ssl  on;
    ssl_certificate  /etc/nginx/ssl/cert.pem;
    ssl_certificate_key  /etc/nginx/ssl/cert.key;
    ssl_session_timeout  5m;

    ssl_protocols  SSLv3 TLSv1;

    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP:!kEDH;
    ssl_prefer_server_ciphers   on;

    location / {
        proxy_pass         http://127.0.0.1:9010;
        proxy_redirect     off;

        client_max_body_size 2m;
        error_page         413 =200 /errors/413;

        proxy_set_header   X-Real-IP          $remote_addr;
        proxy_set_header   Host               $host;
        proxy_set_header   X-Forwarded-Ssl    on;
        proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
    }
}

Thank you very much for your help ! :)

Cyril N.
  • 624
  • 1
  • 10
  • 36

1 Answers1

1

Refer to the Nginx Documentation the client_max_body_size directive can be used in the server block also.

Sameer
  • 4,118
  • 2
  • 17
  • 11
  • yeah I saw that, but I'd like to change the restriction based to the url, without having to repeat the Proxy informations. – Cyril N. Feb 06 '12 at 12:19