我想啓用大文件上傳到一個位置,然後該位置被重寫到另一個位置。看起來重寫是重置其他配置。如何在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