Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;


    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_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 ! :)

share|improve this question

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

share|improve this answer
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 6 '12 at 12:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.