前言 Nginx
是一款高性能、可靠的Web服务器软件,同时用作文件上传和下载
配置 系统版本 [root@127 ~] CentOS Linux release 8.5.2111
创建用户
创建目录 [root@127 ~] [root@127 ~] [root@127 ~] [root@127 upload] [root@127 upload] [root@127 export ] . ├── share │ └── upload └── tmp └── upload ├── 0 ├── 1 ├── 2 ├── 3 ├── 4 ├── 5 ├── 6 ├── 7 ├── 8 ├── 9 └── state 15 directories, 0 files
安装nginx [root@127 ~] [root@127 ~] [root@127 ~] [root@127 ~] [root@127 thb] [root@127 thb] [root@127 thb] [root@127 thb] [root@127 thb] [root@127 nginx-1.17.7] [root@127 nginx-1.17.7] [root@127 nginx-1.17.7] [root@127 nginx] worker_processes 4; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upload_progress proxied 8m; server { listen 80; auth_basic "Please input password" ; auth_basic_user_file /etc/nginx/passwd/testpwd; client_max_body_size 100g; location /upload { upload_pass /upload.php; upload_resumable on; upload_store /export/tmp/upload 1; upload_state_store /export/tmp/upload/state; upload_store_access all:r; 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 ; 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$" ; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ; include fastcgi_params; } location /myfiles { alias /export/share/upload/; index index.html; autoindex on; autoindex_exact_size off; } } }
编辑上传文件 [root@127 nginx] [root@127 html] 50x.html index.html [root@127 html] [root@127 html] <?php $header_prefix = 'file' ;$slots = 6 ; ?> <html> <head> <title>Test upload</title> </head> <body> <?php if ($_POST ){ echo "<h3>Uploaded files:</h3>" ; echo "<table border=\"2\" cellpadding=\"2\">" ; echo "<tr><td>Name</td><td>Location</td><td>Content type</td><td>MD5</td><td>Size</td><td>Scp Command</td><td>Wget Command</tr>" ; for ($i =1 ;$i<=$slots;$i++){ $key = $header_prefix .$i ; if (array_key_exists($key ."_name" , $_POST ) && array_key_exists($key ."_path" ,$_POST )) { $tmp_name = $_POST [$key ."_path" ]; $name = $_POST [$key ."_name" ]; $content_type = $_POST [$key ."_content_type" ]; $md5 = $_POST [$key ."_md5" ]; $size = $_POST [$key ."_size" ]; $final_path = "/export/share/upload" ; if (copy($tmp_name , "$final_path /$name " )) { echo "SUCCESS!" ; } else { echo "FAIL!" ; } $scp_cmd = "scp team@***:/export/share/upload/$name ." ; $wget_cmd = "wget http://***/files/upload/$name " ; echo "<tr><td>$name </td><td>$final_path </td><td>$content_type </td><td>$md5 </td><td>$size </td><td>$scp_cmd </td><td>$wget_cmd </td>" ; } } echo "</table>" ; }else{?> <h3>Select files to upload</h3> <form name="upload" method="POST" enctype="multipart/form-data" action="/upload" > <input type="file" name="file1" ><br> <input type="file" name="file2" ><br> <input type="file" name="file3" ><br> <input type="file" name="file4" ><br> <input type="file" name="file5" ><br> <input type="file" name="file6" ><br> <input type="submit" name="submit" value="Upload" > <input type="hidden" name="test" value="value" > </form> <?php } ?> </body> </html>
增加nginx网页登录验证 [root@127 ~] [root@127 ~] [root@127 ~] New password: Re-type new password: Adding password for user user1
增加nginx启动文件 [root@127 ~] [root@127 ~] [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
PHP安装 [root@127 thb] [root@127 thb] [root@127 thb] [root@127 thb] [root@127 ~] [root@127 ~] [root@127 ~] [root@127 php-5.4.7] [root@127 php-5.4.7] [root@127 ~] [PHP Modules] Core ctype date dom ereg fileinfo filter hash iconv json libxml pcre PDO pdo_sqlite Phar posix Reflection session SimpleXML SPL sqlite3 standard tokenizer xml xmlreader xmlwriter [Zend Modules] [root@127 ~] [root@127 ~] [root@127 php] man [root@127 ~] /usr/share/doc/php-fpm/php-fpm.conf.default [root@127 ~] [root@127 php-fpm] php-fpm.conf.default www.conf.default [root@127 php-fpm] [root@127 php-fpm] [root@127 php-fpm] ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; ; All relative paths in this configuration file are relative to PHP's install ; prefix (/usr). This prefix can be dynamically changed by using the ; ' -p' argument from the command line. ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;; [global] ; Pid file ; Note: the default prefix is /var ; Default Value: none ;pid = run/php-fpm.pid user = nginx group = nginx ...
启动php-fpm服务
启动nginx服务
测试