Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Upload and download the full version of nginx files

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

System version:

[root@vhost8 local] # cat / etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

Users are prepared to:

Useradd-s / sbin/nologin-M nginx

Directory and permission preparation

[root@vhost8 local] #

Mkdir-p / export/share/upload/

Mkdir-p / export/tmp/upload/

Cd / export/tmp/upload/

Mkdir 0 1 2 3 4 5 6 7 8 9 state

Chown-R nginx:nginx / export/

[root@vhost8 export] # tree

.

├── share

│ └── upload

│ ├── eclipse-cpp-2019-09-R-win32-x86_64.zip

└── tmp

└── upload

├── 0

│ ├── 0001559170

├── 1

│ ├── 0000000001

├── 2

├── 3

├── 4

├── 5

├── 6

├── 7

├── 8

├── 9

└── state

15 directories, 26 files

[root@vhost8 local] #

Nginx installation:

Yum remove nginx

Yum-y install gcc gcc-c++ autoconf automake gd gd-devel zlib zlib-devel openssl openssl-devel pcre-devel

Mkdir / root/thb

Cd / root/thb

Wget http://nginx.org/download/nginx-1.17.7.tar.gz

Git clone https://github.com/hongzhidao/nginx-upload-module.git

Git clone https://github.com/masterzen/nginx-upload-progress-module.git

Tar-xzvf nginx-1.17.7.tar.gz

Cd nginx-1.17.7/

. / configure-- with-debug-- prefix=/etc/nginx-- sbin-path=/usr/sbin/nginx-- conf-path=/etc/nginx/nginx.conf-- error-log-path=/var/log/nginx/error.log-- http-log-path=/var/log/nginx/access.log-- pid-path=/var/run/nginx.pid-- lock-path=/var/run/nginx.lock-- http-client-body-temp-path=/var/cache/nginx/client_temp -- http-proxy-temp-path=/var/cache/nginx/proxy_temp-- http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp-- http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp-- http-scgi-temp-path=/var/cache/nginx/scgi_temp-- user=nginx-- group=nginx-- add-module=/root/thb/nginx-upload-module-- add-module=/root/thb/nginx-upload-progress-module-- with-stream -with-http_image_filter_module-with-http_ssl_module-with-http_realip_module-with-http_addition_module-with-http_sub_module-with-http_dav_module-with-http_flv_module-with-http_mp4_module-with-http_gunzip_module-with-http_gzip_static_module-with-http_random_index_module with-http_secure_link_module with-http _ stub_status_module-- with-http_auth_request_module-- with-file-aio-- with-cc-opt='-Wno-format-security-Wno-unused-but-set-variable-Wno-unused-result-D NGX_HAVE_OPENSSL_MD5_H=1-D NGX_OPENSSL_MD5=1-D NGX_HAVE_OPENSSL_SHA1_H=1-O2-g-pipe-Wp -D_FORTIFY_SOURCE=2-fexceptions-fstack-protector-param=ssp-buffer-size=4-M64-mtune=generic'

Make & & make install

Modify the nginx configuration:

Cd / etc/nginx/

Vi nginx.conf

[root@vhost8 nginx] # cat nginx.conf

Worker_processes 4

# error_log logs/error.log

# error_log logs/error.log notice

# error_log logs/error.log info

# pid logs/nginx.pid

Events {

Worker_connections 1024

}

Http {

Include mime.types

Default_type application/octet-stream

# log_format main'$remote_addr-$remote_user [$time_local] "$request"'

#'$status $body_bytes_sent "$http_referer"'

#'"$http_user_agent"$http_x_forwarded_for"'

# access_log logs/access.log main

Sendfile on

# tcp_nopush on

# keepalive_timeout 0

Keepalive_timeout 65

Upload_progress proxied 8m

# gzip on

Server {

Listen 80

Auth_basic "Please input password"; # here is the message for verification

Auth_basic_user_file / etc/nginx/passwd/testpwd

# upload

Client_max_body_size 100g; # this configuration indicates the maximum upload size, but I have not verified whether 100g files can be transferred

# Upload form should be submitted to this location

Location / upload {

# Pass altered request body to this location

Upload_pass / upload.php

# enable resumable

Upload_resumable on

# Store files to this directory

# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist

# remember to modify the read and write permissions of the directory

Upload_store / export/tmp/upload 1

Upload_state_store / export/tmp/upload/state

# Allow uploaded files to be read by all

Upload_store_access all:r

# 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$"

}

Location ~\ .php$ {

# fastcgi_pass unix:/run/php-fpm/php-fpm.sock

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

# fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name

Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name

Include fastcgi_params

}

Location / myfiles {

Alias / export/share/upload/; # file storage directory, note that it ends with'/'

Index index.html; # if there is index.html in the file storage directory, it will jump to index.html

Autoindex on; # automatically lists files in the directory

Autoindex_exact_size off; # file sizes are displayed in G, M format instead of Bytes

}

}

}

[root@vhost8 local] #

Edit uploaded files

[root@vhost8 local] #

Cd / etc/nginx/html

Vi upload.php

[root@vhost8 html] # cat upload.php

Test upload

Select files to upload

[root@vhost8 local] #

Add login authentication for nginx web pages

Yum-y install httpd-tools

Mkdir-p / etc/nginx/passwd/

Htpasswd-c / etc/nginx/passwd/testpwd user1

Enter the user1 login password twice

Add nginx startup file

[root@vhost8 local] #

Vi / lib/systemd/system/nginx.service

[root@vhost8 local] # cat / lib/systemd/system/nginx.service

[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

# Nginx will fail to start if / run/nginx.pid already exists but has the wrong

# SELinux context. This might happen when running `nginx-t` from the cmdline.

# https://bugzilla.redhat.com/show_bug.cgi?id=1268621

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

[root@vhost8 local] #

Php installation

[root@vhost8 nginx] #

Yum-y install gcc automake autoconf libtool make

Yum-y install gcc gcc-c++ glibc

Yum-y install libmcrypt libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

Cd ~

Wget https://museum.php.net/php5/php-5.4.7.tar.gz

Tar-xzvf php-5.4.7.tar.gz

Cd php-5.4.7

. / configure-- prefix=/usr/local/php-- enable-fpm-- with-mcrypt-- enable-mbstring-- disable-pdo-- with-curl-- disable-debug-- disable-rpath-- enable-inline-optimization-- with-bz2-- with-zlib-- enable-sockets-- enable-sysvsem-- enable-sysvshm-- enable-pcntl-- enable-mbregex-with-mhash-- enable-zip-- with-pcre-regex-- with-mysql-- with-mysqli-with-gd-- with-jpeg-dir

Make all install

Cd / usr/local/php

Cp etc/php-fpm.conf.default etc/php-fpm.conf

Vi etc/php-fpm.conf

Modify

User = nginx

Group = nginx

Start the php-fpm service:

Cd / usr/local/php

. / sbin/php-fpm &

Start nginx:

[root@vhost8 local] #

Systemctl enable nginx.service

Systemctl start nginx

Systemctl status nginx

File browsing:

Http://192.168.187.137/myfiles/

File upload:

Http://192.168.187.137/upload.php

Reference:

Https://miopas.github.io/2018/07/24/nginx-file-server-upload/

Https://blog.csdn.net/bigtree_3721/article/details/79870937

Https://www.yanxurui.cc/posts/server/2017-03-21-NGINX-as-a-file-server/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report