# nginx-demo **Repository Path**: w211111/nginx-demo ## Basic Information - **Project Name**: nginx-demo - **Description**: nginx下载&上传文件配置 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-05-07 - **Last Updated**: 2023-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # nginx 配置文件下载&上传 ## 编译的时候加上传模块 ``` ./configure --prefix=/usr/local/nginx --add-module=../nginx-upload-module make && make install ``` ## 配置成服务启动 ``` cp nginx.service /usr/lib/systemd/system/ chmod u+x /usr/lib/systemd/system/nginx.service systemctl daemon-reload ``` ## 上传 ``` location /upload { if ($request_method = 'POST'){ # Pass altered request body to this location upload_pass @test; upload_store /home/zzhwaxy; upload_store_access user:rw; # Set specified fields in request body 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; # Inform backend about hash and size of a file upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5; upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size; upload_pass_form_field "^submit$|^description$"; } } # Pass altered request body to a backend location @test { proxy_pass http://localhost:80; return 200; } ``` ## 下载 ``` location ^~ /download/ { alias /home/zzhwaxy/; if ($request_filename ~* ^.*?\.(html|doc|pdf|zip|docx|txt)$) { add_header Content-Disposition attachment; add_header Content-Type application/octet-stream; } sendfile on; # 开启高效文件传输模式 autoindex on; # 开启目录文件列表 autoindex_exact_size off; # 关闭详细文件大小统计 autoindex_localtime on; # 显示的文件时间为文件的服务器时间 charset utf-8,gbk; # 避免中文乱码 } ``` ## php-fpm 安装 ``` sudo apt-get install php-fpm service php7.4-fpm status ps -ef | grep php-fpm ``` ## 解决权限问题 ``` chmod -R 777 /usr/local/nginx/html ```