背景:有时候有这样一个需求,团队中有新人进来须要一些软件好比jdk,eclipse等开发工具及软件须要共享等等须要考虑可以经过浏览器的方式访问,而且可以直接将软件下载下来 这时候就须要考虑搭建ftp服务器了html
原材料:node
centos6.5以上nginx
1.首先判断是否安装vsftpd服务 能够经过命令查看centos
ps -ef|grep vsftpd
2.若是未安装vsftpd 经过命令安装浏览器
# 安装vsftpd yum -y install vsftpd # 启动 service vsftpd start # 开启启动 chkconfig vsftpd on
由于要考虑到用浏览器的方式访问 因此须要经过nginx进行转发bash
#安装nginx yum install nginx
1.对nginx配置以下:服务器
nginx.conf:app
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user root; worker_processes 4; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. 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; 17,0-1 顶端
conf.d/default.conf配置以下:eclipse
server { listen 80; server_name localhost; autoindex on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /home/cdn;//静态资源 index index.html index.htm; } location ~* \.(eot|ttf|woff|svg|otf)$ { root /home/cdn; index index.html index.htm; add_header Access-Control-Allow-Origin *; } # error_page 404 /404.html; # location = /40x.html { # } #error_page 500 502 503 504 /50x.html; # location = /50x.html { # } "conf.d/default.conf" 32L, 696C 1,5 顶端
/etc/vsftpd/vsftpd.conf文件配置以下:tcp
anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 anon_mkdir_write_enable=YES dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES chroot_list_enable=YES chroot_list_file=/etc/vsftpd/chroot_list listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES
/etc/vsftpd/chroot_list文件配置以下:添加ftp用户cdn
cdn
2.给目录受权要在/home/cdn 目录给予755权限
至此ftp已经搭建好了 咱们能够在浏览器上能够访问了输入http://192.168.102.240以下:
若是访问出现 directory index of "/data/cdn/" is forbidden错误
在nginx中加上 autoindex on;
server {
listen 80;
server_name _;
autoindex on;
root /usr/share/nginx/html;
}
接下来咱们须要配置用户,能够经过客户端工具链接进行文件上传操做
useradd cdn -d /data/cdn/ -s /sbin/nologin ; //为用户cdn建立/data/cdn/ 目录 chown -R cdn /data/cdn/ ;//给/data/cdn受权给cdn用户 chmod -R 777 /data/cdn/
为cdn用户设置口令密码执行下面的命令
passwd cdn;
最后咱们经过用户名和密码就能够连上服务器端了
另外考虑到须要经过浏览器端下载文件 或者上传文件,由于经过nginx代理 nginx默认对上传文件大小设置成1M, 因此须要进行配置
location / { root /data/cdn; index index.html index.htm; client_max_body_size 1000m; }
至此cdn 服务器搭建完成
这里有可能在客户端链接ftp服务器链接不上 显示没法列出目录,主要缘由多是防火墙致使,解决方案将客户端传输模式改成主动链接
命令行输入ftp命令 open 111.120.230.11;//打开ftp服务器地址 输入用户名和密码 put hello.txt;//将文件上传到ftp服务器 get hello.txt;//从ftp服务器下载文件 lcd;//列出ftp文件目录