Nginx+vsftpd

1、安裝Nginx

  • 關閉selinux和firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
systemctl disable firewalld
  • 時間同步
yum -y install ntpdate
ntpdate ntp1.aliyun.com
  • 安裝nginx
yum -y install pcre pcre-devel openssl openssl-devel gcc
useradd nginx -s /sbin/nologin -M
wget http://nginx.org/download/nginx-1.13.11.tar.gz
tar xf nginx-1.13.11.tar.gz
cd nginx-1.13.11
./configure --user=nginx --group=nginx --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd /opt/nginx/sbin/
ln -s /opt/nginx/sbin/* /usr/local/sbin/
  • 修改配置文件
cd /opt/nginx/conf/
mv nginx.conf nginx.conf_bak
cat <<EOF > /opt/nginx/conf/nginx.conf

user  virtual;
worker_processes  2;


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  65;
    autoindex on;
    gzip  on;

    server {
        listen       80;
        server_name  websftp.liveyu.com;
        charset utf-8;
        access_log  logs/host.access.log  main;
        location / {
            root   /data/ftproot;
            index  index.html index.php index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
EOF
  • 啓動nginx
nginx -t
nginx

 

2、安裝vsftpd

  • 安裝vsftpd
yum -y install vsftpd
mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_bak
grep -v "#" /etc/vsftpd/vsftpd.conf_bak > /etc/vsftpd/vsftpd.conf
  • 安裝ftp客戶端
yum -y install ftp
  • 建立用於進行FTP認證的用戶數據庫文件,其中奇數行爲帳戶名,偶數行爲密碼 
cd /etc/vsftpd/
# 建立用於進行FTP認證的用戶數據庫文件,其中奇數行爲帳戶名,偶數行爲密碼
cat <<EOF > vuser.list
admin
123
EOF
  • 使用db_load命令用哈希(hash)算法將原始的明文信息文件轉換成數據庫文件
# 使用db_load命令用哈希(hash)算法將原始的明文信息文件轉換成數據庫文件
db_load -T -t hash -f vuser.list vuser.db
file vuser.db
chmod 600 vuser.db
rm -f vuser.list
  • 建立ftp虛擬用戶
useradd -d /var/ftproot -s /sbin/nologin virtual
ls -ld /var/ftproot/
chmod -Rf 755 /var/ftproot/

yum -y install pam* db4*

vim /etc/pam.d/vsftpd.vu
auth       required     pam_userdb.so db=/etc/vsftpd/vuser
account    required     pam_userdb.so db=/etc/vsftpd/vuser


mkdir /etc/vsftpd/vusers_dir/
cd /etc/vsftpd/vusers_dir/
touch admin
vim admin        # 有上傳/下載/修改權限

anon_world_readable_only=NO        # 匿名用戶能夠瀏覽FTP目錄和下載文件
write_enable=YES                # 設置可寫權限
anon_upload_enable=YES            # 是否容許匿名用戶上傳文件
anon_mkdir_write_enable=YES        # 是否容許匿名用戶建立目錄
anon_other_write_enable=YES        # 是否開放匿名用戶的其餘寫入權限(包括重命名、刪除等操做權限)
local_root=/data/ftproot/        # 本地用戶的FTP根目錄

cat /etc/vsftpd/vsftpd.conf

anonymous_enable=NO                # 是否容許匿名用戶訪問
local_enable=YES                # 是否容許本地用戶登錄FTP
guest_enable=YES                # 開啓虛擬用戶模式
guest_username=virtual            # 指定虛擬用戶帳戶
allow_writeable_chroot=YES      # 容許對禁錮的FTP根目錄執行寫入操做,並且不拒絕用戶的登陸請求
write_enable=YES                # 設置可寫權限
local_umask=022                    # 匿名用戶上傳文件的umask值
dirmessage_enable=YES            # 
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO                        # 是否以獨立運行的方式監聽服務
listen_ipv6=YES
pam_service_name=vsftpd.vu        # 指定PAM文件
userlist_enable=YES                # 開啓用戶做用名單文件功能
tcp_wrappers=YES
user_config_dir=/etc/vsftpd/vusers_dir


systemctl restart vsftpd
systemctl enable vsftpd
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息