vsftpd
查看是否已安装 vsftpd
rpm -qa | grep vsftpd
卸载 vsftpd
yum remove vsftpd
安装
yum install -y vsftpd
修改配置文件
vim /etc/vsftpd/vsftpd.conf
# 关闭匿名登录,输入 /anonymous_enable= 进行搜索
anonymous_enable=NO
# 限制用户只能在家目录下,不能切换到其他地方。输入 /chroot_local_user= 进行搜索
chroot_local_user=YES
# 允许用户在家目录上传文件,创建文件夹等。输入 GG 跳到文件的最后一行添加
allow_writeable_chroot=YES
添加用户
# 添加一个用户名为 ftpuser 的用户,家目录为 /ftpfile,不允许通过 shell 登录
useradd ftpuser -d /ftpfile -s /sbin/nologin
# 为用户设置 ftp 密码
passwd ftpuser
# 设置用户家目录为 777 否则无法上传文件,-R 递归设置
chmod 777 -R /ftpfile
重启 vsftpd
systemctl restart vsftpd
使用新创建的账号连接 vsftpd
使用 FileZilla 输入主机、用户名、密码,连接测试
Nginx
创建站点
注意,根目录需要设置为用户家目录,如 /ftpfile
设置站点为 ftp 公共访问站点
修改配置文件,在 server 内部新增
location /
{
# 防止非ascii(中文等)字符乱码
charset UTF-8;
# 开启目录浏览
autoindex on;
# 关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为B
autoindex_exact_size off;
}
设置站点需要使用账号密码才能访问
安装 htppasswd 工具
yum -y install httpd-tools
生成用户名和密码到指定文件中
# 创建一个文件夹,专门用于保存 nginx 的账号密码
mkdir -p /data/nginx/passwd
# 使用 htpasswd 创建一个用户名和密码,这里创建的用户名为 sam
htpasswd -c /data/nginx/passwd/sam sam
配置 Nginx,需要验证才能访问
在 location 上新增
# 进行身份验证时的提示语,仅部分浏览器支持
auth_basic "authentication";
# 密码文件的位置
auth_basic_user_file /data/nginx/passwd/sam;