1. Before this, our nginx and FTP server have been configured, so now we will get it through and make it a file server. For example, a picture server.
We create a file conf file
sudo vim image.imooc.com.conf
Use the configuration file we mentioned earlier
sudo cat img.happymmall.com.conf
server {
listen 80;
autoindex off;
server_name image.imooc.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
deny all;
}
location / {
root /ftpfile/;
add_header Access-Control-Allow-Origin *;
}
}
Save and exit
:wq
2. Restart nginx
cd ..
cd ..
ll
cd sbin/
sudo ./nginx -s reload
3. Let's visit and test
4、
sudo cat ../conf/vhost/image.imooc.com.conf
5. Let's connect to the ftp server
We can access this picture directly through image.imooc.com/boy.jpg
We will use some open source packages of Apache or FTP in the project, and then we will use the tools in it. When uploading a picture, we will call the FTP service and upload the picture to the FTP server. At this time, we can get the file name after uploading, as well as its prefix. The prefix can be configured in the project through dynamic configuration. We have got the complete URL of the uploaded image. Then we can save this URL.
The above is the Linux-related knowledge shared by Liangxu Tutorial Network for all friends.