Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using nginx with upload progress extension and some rewrite-clauses. Everything works fine, as long as my upload form uploads to a php file (<form action="myphpfile.php" ... >). But when I use an html-file in my action parameter (<form action="myhtmlfile.htm" ...>) I only get "({status: starting})" by requesting the upload status. But... all my pages are rewritten from htm to php using the following location-section in my nginx-conf:

location ~ \.(php|htm)$ {

    rewrite ^/([a-zA-Z0-9]+).htm$ /index.php?page=$1 last;

    client_max_body_size 0;

    include /etc/nginx/fastcgi_params;

    track_uploads uploads 30s;

}

Is there anything wrong with my location- or rewrite-clause? But... these combination works for anything else, thus I'm currently a bit confused why I only get the correct status by using php-files in form's action-parameter.

Edit: My full configuration is as follows:

user  nginx;
worker_processes  1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    upload_progress uploads 1m;

    server {

        listen       80;
        server_name  localhost;
        server_name_in_redirect off;

        client_header_timeout 800;
        client_body_timeout 800;

        location ~* ^.+.(css|js|ico|txt|png|jpg)$ {
            access_log off;
            expires 30d;
            root /var/www;
        }

        location ~ \.(php|htm)$ {

            rewrite ^/([a-zA-Z0-9]+).htm$ /index.php?page=$1 last;

            client_max_body_size 0;

            include /etc/nginx/fastcgi_params;

            track_uploads uploads 30s;

        }

        location = /progress.htm {
            report_uploads uploads;
        }

        location ~ /([a-zA-Z0-9]+) {
            include /etc/nginx/fastcgi_params;
        }

        location / {
            rewrite ^ /index.htm permanent;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root /usr/share/nginx/html;
        }

        location ~ /\.ht {
            deny all;
        }

    }

}
share|improve this question
    
Do you get any logs in your error log file? –  Hex Oct 26 '12 at 18:33
    
No... there are no errors in my log-file(s). –  Nrgyzer Oct 26 '12 at 20:26

1 Answer 1

The basis of your logic is wrong. Nginx can only ever use one location per request, you cannot define a location, configure something there and then rewrite the request. When you do this Nginx will disregard everything in that location and only use the location you rewrote to.

You need to have your track_uploads directive in the same location as your fastcgi_pass, otherwise Nginx will think that you're trying to POST to a static location.

Please post your entire server block if you need further help.

share|improve this answer
    
I added the full configuration above... –  Nrgyzer Oct 26 '12 at 20:26

Your Answer

 
discard

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.