第1章 概述
有些软件、文件想要通过一些便捷的方式公开下载链接,不想要用户登录,方便下载就行,就像是服务器镜像站一样。
小编了解到可以通过nginx简单的配置部署实现搭建类似的下载站,在这里分享给大家。
第2章 环境准备
演示环境我们使用了一台RockyLinux 9.5服务器进行部署。
访问逻辑如下,管理员访问服务器上传文件,用户访问web下载文件。
第3章 环境部署
1、使用ssh远程工具,远程到服务器。
2、通过yum工具安装Nginx。
[root@localhost ~]# yum install nginx -y
3、创建数据根目录,这里我在opt目录下创建了data目录作为数据的根目录。
[root@localhost ~]# mkdir /opt/data
4、创建nginx配置文件。
[root@localhost ~]# vim /etc/nginx/conf.d/server.conf
配置文件内容如下:
server {
listen 80; ##指定服务端口
root /opt/data; ##指定根目录
location / {
autoindex on; ##自动生成主目录
autoindex_localtime on; ##使用本地时间
}
}
5、使用“nginx -t”检验配置是否正确。
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
6、启动nginx 服务。
[root@localhost ~]# systemctl start nginx
7、添加防火墙端口例外。
[root@localhost ~]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
8、访问网页测试。
9、使用远程工具将需要公开下载的文件上次到/opt/data目录
10、刷新网页,显示文件/目录,点击对应的链接进行下载。
第4章 总结
希望通过此篇文章对于使用Nginx部署下载站的配置可以帮助到有相关需求的朋友。小编在这里愿在为梦想努力拼搏奋斗的工程师们“轻轻松松的工作,快快乐乐的生活”。