• 150455

    文章

  • 1095

    评论

  • 13

    友链

  • 最近新加了换肤功能,大家多来逛逛吧~~~~
  • 喜欢这个网站的朋友可以加一下QQ群,我们一起交流技术。

centos7.6安装FTP:NGINX+Vsftpd


系统:centos 7.6

软件:VSFTP、NGINX

配置NGINX网站并配置FTP权限,可通过FTP上传文件到NGINX网站

首先配置好镜像源,关闭seLinux 及防火墙安装NGINX及vsftp,将NGINX根目录设置成ftp的访问根目录

[root@localhost ~]#setenforce 0
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#systemctl disable firewalld
[root@localhost ~]# yum -y install nginx vsftpd  db4-utils
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

配置NGINX

[root@localhost nginx]# vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;


    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80 default_server;
        server_name  your_domain_name;          #你的域名地址
        root         /your_path;

        include /etc/nginx/default.d/*.conf;

        location / {
                autoindex on;
                autoindex_exact_size off;
                autoindex_localtime on;
                charset utf-8,gbk;

        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }



}

 

配置vsftp配置文件,/etc/vsftpd/vsftpd.conf

[root@localhost vsftpd]# cd /etc/vsftpd/

[root@localhost vsftpd]# vim vsftpd.conf

# Example config file /etc/vsftpd/vsftpd.conf

# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES      #配置匿名用户可访问
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
anon_upload_enable=YES   #配置匿名用户可以上传文件
anon_root=/data  #配置匿名用户登录后根目录
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=NO     #配置匿名用户不允许创建文件夹
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
#chroot_writeable_chroot=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list   #需要在/etc/vsftpd/下单独创建chroot_list配置文件,用来限制用户是否可以进入根目录的上一级目录
#
allow_writeable_chroot=YES
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
local_root=/data         #配置ftp登录后根目录为/data,此目录与NGINX根目录相同
#virtual_use_local_privs=YES
guest_enable=YES          #使用虚拟用户登录
guest_username=aaa        #使用系统用户aaa,用来创建虚拟用户
virtual_use_local_privs=YES    
user_config_dir=/etc/vsftpd/conf   #匿名用户配置所在文件目录



[root@localhost vsftpd]# mkdir /etc/vsftpd/conf

[root@localhost vsftpd]# cd /etc/vsftpd/conf

[root@localhost conf]#vim admin
local_root=/data
virtual_use_local_privs=YES
write_enable=YES
download_enable=YES


 

创建虚拟用户的配置文件(任意命名)一行用户名,一行密码,如下:admin为虚拟用户名,Password123为admin的密码,anonymous为虚拟用户名,123Password为anonymous的密码,如果需要修改虚拟用户的密码,就删除/etc/vsftpd/生成的db文件,在vsuser中修改之后,重新生成一个db文件即可

[root@localhost vsftpd]# vim vsuser
admin
Password123
anonymous
123Password
[root@localhost vsftpd]# db_load -T -t hash -f /etc/vsftpd/vsuser /etc/vsftpd/vuser.db     #生成虚拟用户口令认证文件(生成db文件)

[root@localhost vsftpd]# ls
conf  ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh  vsuser  vuser.db


[root@localhost vsftpd]# systemctl restart vsftpd

编辑vsftpd的PAM认证文件(vsftp默认PAM认证文件为/etc/pam.d/vsftp)

[root@localhost vsftpd]# vim /etc/pam.d/vsftpd
#%PAM-1.0
auth       sufficient   pam_userdb.so   db=/etc/vsftpd/vuser      #此处为添加项,db的文件名要对应/etc/vsftd/vuser.db
account    sufficient   pam_userdb.so   db=/etc/vsftpd/vuser      #此处为添加项,db的文件名要对应/etc/vsftd/vuser.db
session    optional     pam_keyinit.so    force revoke
auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required     pam_shells.so
auth       include      password-auth
account    include      password-auth
session    required     pam_loginuid.so
session    include      password-auth
[root@localhost vsftpd]#systemctl restart vsftpd

 

设置虚拟用户登录后权限。admin虚拟用户登录后有所有权限,创建\删除 文件夹\文件;anonymous虚拟用户只可以上传文件,无法删除创建文件夹,无法删除文件

[root@localhost conf]# pwd
/etc/vsftpd/conf


[root@localhost conf]# cat admin 
local_root=/test_resources
virtual_use_local_privs=YES
write_enable=YES
download_enable=YES


[root@localhost conf]# cat admin 
local_root=/test_resources
virtual_use_local_privs=YES
write_enable=YES
download_enable=YES
[root@localhost conf]# cat anonymous 
local_root=/test_resources
virtual_use_local_privs=NO
write_enable=YES
anon_upload_enable=yes
anon_world_readable_only=NO
download_enable=YES
anon_umask=022
anon_mkdir_write_enable=NO

重启vsftpd服务,之后可以通过ftp上传文件,然后其他用户可以通过浏览器访问域名访问到此目录进行下载


695856371Web网页设计师②群 | 喜欢本站的朋友可以收藏本站,或者加入我们大家一起来交流技术!

0条评论

Loading...


发表评论

电子邮件地址不会被公开。 必填项已用*标注

自定义皮肤 主体内容背景
打开支付宝扫码付款购买视频教程
遇到问题联系客服QQ:419400980
注册梁钟霖个人博客