沒事誰折騰這鬼玩意哦。。。還不是由於bug。html
咱們的應用,用戶頭像是存在ftp上的。以前的ftp服務器是一臺windows,咱們後臺服務器程序收到用戶上傳頭像的請求時,會用一個ROOT/ROOT的帳戶,鏈接ftp服務器。linux
獲取到鏈接後,即進行上傳。windows
上傳:上傳文件則存放在ROOT用戶的home 目錄(在windows上裝的是server-U來充當ftp服務器,因此就是在Server-U裏面配置了ROOT用戶的home目錄)。服務器
上傳完成後,會獲得一個ftp協議類型的url。範例如:session
ftp://10.10.20.2/userphoto/user7.png。app
客戶端拿到該url後,即用ftp客戶端的庫鏈接該url,獲取到文件流,下載下來,進行展現。socket
這兩天,ftp服務器從windows變到了redhat上。今天下午,測試忽然報了個bug過來,說是用戶頭像不能正常展現了。what?因而開始查找問題。async
梳理了半天,發現問題在於:linux上的ftp服務器,採用的是vsftpd軟件。由於配置文件沒配好的緣由,利用前面的「ftp://10.10.20.2/userphoto/user7.png」就訪問不到圖片。tcp
爲何說沒配好呢,一開始報的錯是:FTP 550 Failed to change directoryide
因而按照下面博文裏的進行修改:https://blog.csdn.net/coreyC/article/details/80866533
沒想到一波三折。
關於匿名訪問,若是不成功的話,那麼,請首先去下載一個工具,winscp。
按照下面的方式去進行匿名訪問:
若是匿名登陸失敗的話,會提示具體的緣由。
這個提示,有一個緣由是,匿名用戶的主目錄,主目錄的意思是,每一個用戶登陸進去後所在的目錄,後續的讀取、上傳都會在這個目錄,至關於用戶的base目錄吧。
若是主目錄的權限不夠,就會提示這個問題,通常直接野蠻改成777權限。
至於主目錄在哪? 在配置文件中經過如下選項進行配置:
anon_root=/data/ftp
以下圖所示,須要把主目錄權限改成777,便可匿名上傳:
修改權限的命令:
chmod 777 /data/ftp
下述的報錯也是一樣的問題:
500 OOPS: vsftpd: refusing to run with writable anonymous root
正確的配置貼一份,這份配置再加上,對目錄進行必要的權限設置,基本能夠擺平大多數狀況:
# Example config file /etc/vsftpd/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
# 這裏須要打開,容許匿名訪問 anonymous_enable=YES
#https://blog.csdn.net/bluishglc/article/details/42399439
allow_writeable_chroot=YES
# # Uncomment this to allow local users to log in.
# 以前說到咱們用ROOT/ROOT來訪問ftp,咱們這裏,ROOT/ROOT是咱們的linux能夠登陸的用戶名密碼。要容許這類用戶訪問ftp,須要開啓下面的選項 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.
# 匿名上傳,須要配合write_enable=yes anon_upload_enable=YES
# # Uncomment this if you want the anonymous FTP user to be able to create # new directories.
# 容許匿名用戶建立目錄; anon_mkdir_write_enable=YES
#控制匿名用戶對文件和文件夾的刪除和重命名 anon_other_write_enable=YES
# # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # The target log file can be vsftpd_log_file or xferlog_file. # This depends on setting xferlog_std_format parameter 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 # # The name of log file when xferlog_enable=YES and xferlog_std_format=YES # WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log #xferlog_file=/var/log/xferlog # # Switches between logging into vsftpd_log_file and xferlog_file files. # NO writes to vsftpd_log_file, YES to xferlog_file 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. # 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(). #chroot_local_user=YES #chroot_list_enable=YES # (default follows) #chroot_list_file=/etc/vsftpd/chroot_list # # 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=YES # # This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6 # sockets, 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
#匿名用戶的根目錄。這個很是重要 anon_root=/home/ROOT
#匿名用戶不要密碼就靠這個 no_anon_password=YES
#本地用戶,如咱們上傳用的用戶(ROOT/ROOT)的根目錄。固然,咱們給匿名配了那麼多,估計匿名也能上傳了。 local_root=/home/ROOT
#該選項暫時不太清楚 ftp_username=ROOT
參考資料: