nginx+ftp服务器搭建简易文件服务器

时间:2021-10-06 02:52:57

在做一些小项目和学习项目过程中,学习了通过 nginx 和 FTP 搭建小型文件服务器,记录下:

1.环境

  • 电脑:acer
  • 操作系统:windows 10
  • ftp服务器

2.下载 nginx, 通过双击图标 nginx.exe 或则启动 cmd 命令行启动

3.运行后,浏览器访问 localhost:80,进入主页,完成

nginx+ftp服务器搭建简易文件服务器

4.无法访问时,可能是 80 端口被占用,可以 kill 掉这个任务,但可能是 IIS 服务每次强制更新后就会监听 80 端口

5.这时候,找到 ‘打开或关闭窗口功能’ ,将勾选 Internet Information Services 去掉,估计能解决吧

nginx+ftp服务器搭建简易文件服务器

6.在准备好一个FTP服务器后,可搭建一个简单的文件服务器,文件设置:

image.cat.com.conf : (创建该文件在 nginx/conf/vhost 文件下,方便 nginx.conf 文件中导入)

E:\ftpfile 为 ftpServer 的文件目录

server {
listen 80;
autoindex off;
server_name image.cat.com;
access_log c:/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 E:\ftpfile;
add_header Access-Control-Allow-Origin *;
}
}

hosts:(该文件在本机电脑下的路径为 C:\Windows\System32\drivers\etc)

127.0.0.1 image.cat.com

nginx.conf:

include vhost/*.conf;

7.这时,浏览器访问 image.cat.com/10.jpg, 完成

nginx+ftp服务器搭建简易文件服务器

8.如果访问提示 403 Forbidden,可以检查下 FTP 服务器文件目录存放的位置!