我正在使用nginx上传进度扩展和一些重写子句。 一切正常,只要我上传表单上传到一个PHP文件( <form action="myphpfile.php" ... > )。 但是当我在我的动作参数( <form action="myhtmlfile.htm" ...> )中使用html文件时,我只通过请求上传状态来获得“({status:starting})”。 但是…我所有的网页都是从htm改写为php,使用我的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; }
我的位置或重写条款有什么问题吗? 但是…这些组合适用于其他任何东西,所以我目前有点困惑,为什么我只通过在窗体的action-parameter中使用php-files来获得正确的状态。
编辑:我的完整configuration如下:
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; } } }
你的逻辑的基础是错误的。 Nginx只能为每个请求使用一个位置,你不能定义一个位置,在那里configuration一些东西,然后重写请求。 当你这样做的时候,Nginx会忽略那个地方的所有东西,只使用你重写的位置。
你需要把你的track_uploads指令放在fastcgi_pass所在的位置,否则Nginx会认为你正在尝试POST到一个静态位置。
如果您需要进一步的帮助,请发布您的整个服务器块。