這篇文章的目的是在編譯安裝Nginx的同時,安裝upload和uploadprogress模塊,以及運行Drupal 8所須要的配置。
因爲使用的是Raspberry pi 3B,因此係統用的Raspbian,Debian/Ubuntu應該也是差很少的。php
下載Nginx以及相關模塊css
下載Nginx以及PCRE模塊並解壓。
進入解壓後的Nginx目錄,執行命令:nginx
./configure --prefix=/etc/nginx --with-pcre=/tmp/pcre-8.39 --sbin-path=/usr/sbin/nginx --with-http_ssl_module --add-module=/mnt/sources/nginx-upload-module --add-module=/mnt/sources/nginx-upload-progress-module
第一個參數是Nginx安裝位置,第二個參數是PCRE源文件位置,第三個參數是Nginx啓動的位置。
接着執行 make && make install,便可完成編譯安裝。程序員
Drupal 8運行須要的配置segmentfault
首先須要在nginx.conf的http上下文裏增長一條:app
upload_progress proxied 1m;
這條是表示每上傳1M就更新進度信息。socket
接下來就是Drupal網站的配置:ide
server { server_name d8.local.dev; root /mnt/apps/d8; client_max_body_size 1024m; client_body_buffer_size 2048k; # 這個地址是用來獲取進度信息,proxied是http裏配置的信息。 location ^~ /progress { report_uploads proxied; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Very rarely should these ever be accessed outside of your lan location ~* \.(txt|log)$ { allow 192.168.0.0/16; deny all; } location ~ \..*/.*\.php$ { return 403; } location ~ ^/sites/.*/private/ { return 403; } # Allow "Well-Known URIs" as per RFC 5785 location ~* ^/.well-known/ { allow all; } location ~ (^|/)\. { return 403; } location / { # 若是是自定義字段上傳的文件,就交由下面的代碼處理 if ($query_string ~ "X-Progress-ID=\d+"){ rewrite ^(.*)$ /upload; } try_files $uri /index.php?$query_string; # For Drupal >= 7 } location /upload { # 文件上傳成功後,處理文件的頁面。index.php是Drupal的入口文件 upload_pass /index.php; # 是否附帶QueryString參數 upload_pass_args on; # 臨時存放文件的目錄 upload_store /tmp/nginx_upload; # 存放上傳狀態的目錄,用於斷點續傳 upload_state_store /tmp/nginx_state; # 臨時目錄的權限 upload_store_access user:rw group:rw all:rw; # 提交到後臺的字段名 set $upload_field_name "tmp_file"; # 文件名 upload_set_form_field $upload_field_name.name "$upload_file_name"; # 文件類型 upload_set_form_field $upload_field_name.content_type "$upload_content_type"; # 臨時路徑 upload_set_form_field $upload_field_name.path "$upload_tmp_path"; # 文件MD5信息 upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5"; # 文件大小 upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size"; # 原樣提交到後臺的表單字段,這裏表示全部字段都提交給PHP upload_pass_form_field "^.*$"; upload_cleanup 400 404 499 500-505; } # Don't allow direct access to PHP files in the vendor directory. location ~ /vendor/.*\.php$ { deny all; return 404; } location ~ '\.php$|^/update.php' { fastcgi_split_path_info ^(.+?\.php)(|/.*)$; include fastcgi_params; fastcgi_param HTTP_PROXY ""; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_intercept_errors on; # PHP 7 socket location. fastcgi_pass 127.0.0.1:9090; track_uploads proxied 60s; } location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7 try_files $uri @rewrite; } # Handle private files through Drupal. Private file's path can come # with a language prefix. location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7 try_files $uri /index.php?$query_string; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } }
在Drupal 8裏的具體應用,請看個人另外一篇文章:Drupal 8 結合Nginx實現文件上傳進度,提升上傳文件性能性能
程序員客棧,聚集各路碼農,找到你的靠譜技術小夥伴 http://t.cn/RXz4ONT網站