我想启用大文件上传到一个位置,然后该位置被重写到另一个位置。看起来重写是重置其他配置。如何在nginx中结合rewrite和client_max_body_size?
我的配置:
server {
listen 80;
server_name example.com;
root /var/www;
index index.php;
# this location requires large file upload
location /upload {
client_max_body_size 512M;
rewrite ^(.*)$ /index.php?request=$1 last;
}
# all other locations
location/{
rewrite ^(.*)$ /index.php?request=$1 last;
}
# pass the PHP scripts to FPM
location ~ \.php$ {
include /etc/nginx/includes/php;
}
}
如果我移动client_max_body_size出location
,进入server
,那么它的工作原理。
如果我把它放在location /upload
和location ~ \.php$
,那么它也可以。但我不希望其他位置能够上传大文件。
我在想我可以直接在location /upload
上直接使用PHP,但是一旦我运行重写,它将会寻找另一个位置。这是否意味着我将不得不有两个单独的位置的PHP脚本?重写后有什么办法可以让client_max_body_size
通过其他地方保留?
真棒!第一个似乎正在工作!我认为重定向会导致它进入一个循环,但我猜它何时会在包含它的fcgi_pass中终止它。 – DAB
其实我回来了。我仍然有我的最大身体大小在PHP的位置。我打开了调试日志,看起来有'fastcgi_pass'的php include被忽略,并且重写开始再次测试所有条件。这里是调试日志:https://gist.github.com/macdabby/13832f4257a73f82c01c。我会尝试一些参数,但这似乎也没有工作。 – DAB