Linux搭建简单的http文件服务器
2022/7/26 5:22:47
本文主要是介绍Linux搭建简单的http文件服务器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、CentOS7中安装httpd
通过yum install httpd
[root@cavan rpm]# yum install httpd Repository extras is listed more than once in the configuration MySQL Tools Community 1.0 kB/s | 2.6 kB 00:02 MySQL Tools Community 186 kB/s | 651 kB 00:03 MySQL 5.6 Community Server 4.8 kB/s | 2.6 kB 00:00 Dependencies resolved. =============================================================================================================================== Package Architecture Version Repository Size =============================================================================================================================== Installing: httpd x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 appstream 1.4 M Installing dependencies: apr x86_64 1.6.3-12.el8 appstream 129 k apr-util x86_64 1.6.1-6.el8 appstream 105 k centos-logos-httpd noarch 85.8-2.el8 base 75 k httpd-filesystem noarch 2.4.37-43.module_el8.5.0+1022+b541f3b1 appstream 39 k httpd-tools x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 appstream 107 k mod_http2 x86_64 1.15.7-3.module_el8.4.0+778+c970deab appstream 154 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8 appstream 25 k apr-util-openssl x86_64 1.6.1-6.el8 appstream 27 k Enabling module streams: httpd 2.4 Transaction Summary =============================================================================================================================== Install 9 Packages Total download size: 2.1 M Installed size: 5.6 M Is this ok [y/N]: y Downloading Packages: (1/9): apr-util-1.6.1-6.el8.x86_64.rpm 1.9 MB/s | 105 kB 00:00 (2/9): apr-util-bdb-1.6.1-6.el8.x86_64.rpm 417 kB/s | 25 kB 00:00 (3/9): apr-1.6.3-12.el8.x86_64.rpm 2.1 MB/s | 129 kB 00:00 (4/9): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 942 kB/s | 27 kB 00:00 (5/9): httpd-filesystem-2.4.37-43.module_el8.5.0+1022+b541f3b1.noarch.rpm 827 kB/s | 39 kB 00:00 (6/9): httpd-tools-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64.rpm 3.4 MB/s | 107 kB 00:00 (7/9): mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64.rpm 1.9 MB/s | 154 kB 00:00 (8/9): httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64.rpm 5.4 MB/s | 1.4 MB 00:00 (9/9): centos-logos-httpd-85.8-2.el8.noarch.rpm 251 kB/s | 75 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------- Total 5.0 MB/s | 2.1 MB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.6.3-12.el8.x86_64 1/9 Running scriptlet: apr-1.6.3-12.el8.x86_64 1/9 Installing : apr-util-bdb-1.6.1-6.el8.x86_64 2/9 Installing : apr-util-openssl-1.6.1-6.el8.x86_64 3/9 Installing : apr-util-1.6.1-6.el8.x86_64 4/9 Running scriptlet: apr-util-1.6.1-6.el8.x86_64 4/9 Installing : httpd-tools-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 5/9 Installing : centos-logos-httpd-85.8-2.el8.noarch 6/9 Running scriptlet: httpd-filesystem-2.4.37-43.module_el8.5.0+1022+b541f3b1.noarch 7/9 Installing : httpd-filesystem-2.4.37-43.module_el8.5.0+1022+b541f3b1.noarch 7/9 Installing : mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64 8/9 Installing : httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 9/9 Running scriptlet: httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 9/9 Verifying : apr-1.6.3-12.el8.x86_64 1/9 Verifying : apr-util-1.6.1-6.el8.x86_64 2/9 Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 3/9 Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 4/9 Verifying : httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 5/9 Verifying : httpd-filesystem-2.4.37-43.module_el8.5.0+1022+b541f3b1.noarch 6/9 Verifying : httpd-tools-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 7/9 Verifying : mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64 8/9 Verifying : centos-logos-httpd-85.8-2.el8.noarch 9/9 Installed: apr-1.6.3-12.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 centos-logos-httpd-85.8-2.el8.noarch httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 httpd-filesystem-2.4.37-43.module_el8.5.0+1022+b541f3b1.noarch httpd-tools-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64 Complete!
2、修改配置
httpd的配置文件是/etc/httpd/conf/httpd.conf
vi /etc/httpd/conf/httpd.conf
#服务端口设置为8000 Listen 8000
配置文件里面的内容大同小异,这边不做详细介绍,两者默认的访问端口都是80端口,当然这是可以在配置文件中进行修改的。
3、安装好启动一下
service httpd start
:启动
[root@cavan conf]# service httpd start Redirecting to /bin/systemctl start httpd.service [root@cavan conf]# lsof -i:8000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 27386 root 4u IPv6 90884 0t0 TCP *:irdmi (LISTEN) httpd 27388 apache 4u IPv6 90884 0t0 TCP *:irdmi (LISTEN) httpd 27389 apache 4u IPv6 90884 0t0 TCP *:irdmi (LISTEN) httpd 27390 apache 4u IPv6 90884 0t0 TCP *:irdmi (LISTEN)
service httpd restart
:重新启动
service httpd stop
:停止服务
4、测试
在配置文件中可以发现,服务器默认的访问路径在/var/www/html目录下。
进入/var/www/html目录,新建一个test.sh文件,输入hello
然后,打开命令行Windows+R,输入cmd,执行
curl -o test.sh http://121.43.225.17:8000/test.sh
去C:\Users\cavan盘下,查看下载好文件,如下所示:
下载成功。
只是为了简单实现一台http文件服务器,因此可以在此目录下创建一个软连接来连接文件目录。
192.168.1.10这个节点作为安装包文件目录是/home/nn/package/,然后通过命令ln -s /home/nn/package/ file在/var/www/html/目录下创建了一个软连接。
在浏览器中就可以通过http://192.168.1.10/file访问到文件目录了,如下:
https://www.likecs.com/show-166789.html
这篇关于Linux搭建简单的http文件服务器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-18git仓库有更新,jenkins 自动触发拉代码怎么配置的?-icode9专业技术文章分享
- 2024-12-18Jenkins webhook 方式怎么配置指定的分支?-icode9专业技术文章分享
- 2024-12-13Linux C++项目实战入门教程
- 2024-12-13Linux C++编程项目实战入门教程
- 2024-12-11Linux部署Scrapy教程:新手入门指南
- 2024-12-11怎么将在本地创建的 Maven 仓库迁移到 Linux 服务器上?-icode9专业技术文章分享
- 2024-12-10Linux常用命令
- 2024-12-06谁看谁服! Linux 创始人对于进程和线程的理解是…
- 2024-12-04操作系统教程:新手入门及初级技巧详解
- 2024-12-04操作系统入门:新手必学指南