当前位置: 首页 > Linux

编译安装Nginx并配置运行Drupal8实现上传进度功能

时间:2023-04-06 23:18:30 Linux

本文的目的是在编译安装Nginx的同时安装upload和uploadprogress模块??以及运行Drupal8所需的配置。由于使用的是Raspberrypi3B,所以系统中使用的Raspbian和Debian/Ubuntu应该是差不多的。下载Nginx及相关模块下载Nginx和PCRE模块并解压。进入解压后的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安装位置,第二个参数是PCREsource文件位置,第三个参数是Nginx启动的位置。然后执行make&&makeinstall完成编译安装。运行Drupal8所需的配置首先需要在nginx.conf的http上下文中添加一项:upload_progressproxied1m;此项表示每上传1M更新进度信息。接下来是Drupal网站的配置:server{server_named8.local.dev;根/mnt/应用程序/d8;client_max_body_size1024m;client_body_buffer_size2048k;#这个地址是用来获取进度信息的,proxied就是http中配置的信息。location^~/progress{report_uploads代理;}location=/favicon.ico{log_not_found关闭;access_log关闭;}location=/robots.txt{允许所有;log_not_found关闭;access_log关闭;}#很少应该在你的lan位置之外访问这些~*\.(txt|log)${allow192.168.0.0/16;全部拒绝;}位置~\..*/.*\.php${返回403;}location~^/sites/.*/private/{return403;}#根据RFC5785位置允许“Well-KnownURIs”~*^/.well-known/{allowall;}位置~(^|/)\.{返回403;}location/{#如果是自定义字段上传的文件,会被下面的代码处理if($query_string~"X-Progress-ID=\d+"){rewrite^(.*)$/upload;}try_files$uri/index.php?$query_string;#ForDrupal>=7}location/upload{#文件上传成功后,页面对文件进行处理。index.php是Drupal的入口文件upload_pass/index.php;#是否包含QueryString参数upload_pass_argson;#临时文件存放目录upload_store/tmp/nginx_upload;#上传状态存放目录,用于断点续传upload_state_store/tmp/nginx_state;#临时目录权限upload_store_accessuser:rwgroup:rwall: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.sizeupload_file_size";#原样提交给后台的表单字段,这里表示所有字段都提交给PHPupload_pass_form_field"^.*$";上传清理400404499500-505;}#不允许直接访问供应商目录中的PHP文件。location~/vendor/.*\.php${全部拒绝;返回404;}location~'\.php$|^/update.php'{fastcgi_split_path_info^(.+?\.php)(|/.*)$;包括fastcgi_params;fastcgi_paramHTTP_PROXY"";fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_paramPATH_INFO$fastcgi_path_info;fastcgi_paramQUERY_STRING$query_string;fastcgi_intercept_errors开启;#PHP7套接字位置。fastcgi_pass127.0.0.1:9090;track_uploads代理60秒;}location~^/sites/.*/files/styles/{#ForDrupal>=7try_files$uri@rewrite;}#通过Drupal处理私有文件。私人文件的路径可以带有#语言前缀。location~^(/[a-z\-]+)?/system/files/{#ForDrupal>=7try_files$uri/index.php?$query_string;}位置~*\.(js|css|png|jpg|jpeg|gif|ico)${过期最大值;log_not_found关闭;}}在Drupal8中的具体应用可以看我的另一篇文章:Drupal8结合Nginx实现文件上传进度,提升上传文件性能程序员客栈,汇聚各路码农,找你靠谱的技术伙伴http://t.cn/RXz4ONT