Linux如何搭建文件服務(wù)器
搭建簡單文件服務(wù)器
| IP | 環(huán)境 |
|---|---|
| 192.168.200.100 | VMware17 |
基于centos7.9搭建http文件服務(wù)器
安裝httpd
[root@localhost ~]# yum install -y httpd
關(guān)閉防火墻以及selinux
[root@localhost ~]# systemctl stop firewalld;setenforce 0
文件/etc/httpd/conf/httpd.conf中的默認(rèn)參數(shù)(自定義修改)
DocumentRoot "/var/www/html" #這一行指定了文檔根目錄
<Directory "/var/www"> #用于針對指定目錄(在這里是/var/www)設(shè)置訪問控制規(guī)則的開始標(biāo)簽。以下的配置將應(yīng)用于/var/www目錄及其子目錄。
AllowOverride None
# Allow open access:
Require all granted #表示允許所有人訪問/var/www目錄及其子目錄,沒有訪問限制
</Directory>
Listen 80 #默認(rèn)的監(jiān)聽端口,修改80后則需要指定IP:端口進行訪問注釋/etc/httpd/conf.d/welcome.conf文件下的此內(nèi)容,不然就會返回禁止訪問報錯
#<LocationMatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#</LocationMatch>
文件服務(wù)器下創(chuàng)建測試文件
[root@localhost ~]# echo hello > /var/www/html/test.txt
啟動httpd并設(shè)置開機自啟
[root@localhost ~]# systemctl enable --now httpd
訪問界面如下

此時的文件服務(wù)器還不能下載,點擊后會打開該文件

編輯http.conf文件,追加以下內(nèi)容
<FilesMatch "\.(?i:pdf|zip|txt|csv)$">
Header set Content-Disposition "attachment"
</FilesMatch>
當(dāng)有人請求以 .pdf、.zip、.txt 或 .csv 結(jié)尾的文件時,服務(wù)器會設(shè)置 Content-Disposition 標(biāo)頭,強制
將文件作為附件下載,而不是在瀏覽器中直接打開,如果還要添加例如tar、gz等文件后綴可以下載,
則需要在括號內(nèi)添加(?i:pdf|zip|txt|csv|gz|tar)相應(yīng)的后綴[root@localhost ~]# systemctl restart httpd
此時重新打開無痕模式瀏覽器,或者清除緩存再次打開

完善文件服務(wù)器的瀏覽器界面,在http.conf的Directory標(biāo)簽中添加
Options +Indexes:啟用目錄索引,允許顯示目錄內(nèi)容。
IndexOptions FancyIndexing:啟用美化的目錄索引,以改善目錄內(nèi)容的可讀性。
IndexOptions NameWidth=:允許文件名列寬度自動調(diào)整以適應(yīng)不同文件名的長度。
IndexOptions DescriptionWidth=:允許描述列寬度自動調(diào)整以適應(yīng)不同文件描述的長度。
IndexOptions FoldersFirst:將文件夾顯示在文件之前,以提高目錄索引的可讀性。
<Directory /var/www>
AllowOverride None
# Allow open access:
Require all granted
#以下為添加內(nèi)容
Options +Indexes
IndexOptions FancyIndexing NameWidth=* DescriptionWidth=* FoldersFirst
</Directory>[root@localhost ~]# systemctl restart httpd

基于centos7.9搭建nginx文件服務(wù)器
安裝wget命令,需要拉取阿里源的epel源,再下載nginx
[root@localhost ~]# yum install -y wget
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum install -y nginx
[root@localhost ~]# yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.cqu.edu.cn
* updates: mirrors.cqu.edu.cn
Installed Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.20.1
Release : 10.el7
Size : 1.7 M
Repo : installed
From repo : epel
Summary : A high performance web server and reverse proxy server
URL : https://nginx.org
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
: IMAP protocols, with a strong focus on high concurrency, performance and low
: memory usage.修改nginx.conf文件
[root@localhost ~]# vi /etc/nginx/nginx.conf
user nginx; #nginx改為root
#在server配置標(biāo)簽上添加以下內(nèi)容
autoindex on;# 顯示目錄
autoindex_exact_size on;# 顯示文件大小
autoindex_localtime on;# 顯示文件時間
root /opt; #/opt表示你要共享的文件服務(wù)器根目錄啟動nginx,并開機自啟
[root@localhost ~]# systemctl enable --now nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
瀏覽器IP訪問,如果要指定端口,修改Linsten后面的80即可

基于ubuntu2204搭建http文件服務(wù)器
| IP | 環(huán)境 |
|---|---|
| 192.168.200.200 | VMware17 |
安裝apache2
root@huhy:~# apt install -y apache2
root@huhy:~# mkdir /var/www/html/test-file root@huhy:~# chmod 777 /var/www/html/test-file/ root@huhy:~# echo ok > /var/www/html/test-file/test.txt root@huhy:~# vi /etc/apache2/sites-available/000-default.conf DocumentRoot /var/www/html/test-file #修改此參數(shù),就可以指向該文件夾
root@huhy:~# systemctl enable --now apache2 Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable apache2
瀏覽器IP訪問

優(yōu)化界面
root@huhy:~# vi /etc/apache2/apache2.conf
<Directory /var/www/> #對此目錄下生效
Options Indexes FollowSymLinks
AllowOverride None
Require all granted #添加下面兩行
Options +Indexes
IndexOptions FancyIndexing NameWidth=* DescriptionWidth=* FoldersFirst
</Directory>再次訪問

總的來說ubuntu搭建更加簡單一些,做的配置也不多
到此這篇關(guān)于Linux搭建文件服務(wù)器的文章就介紹到這了,更多相關(guān)Linux文件服務(wù)器搭建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux使用vmstat監(jiān)控系統(tǒng)性能的示例方法
vmstat命令是最常見的Linux/Unix監(jiān)控工具,可以展現(xiàn)給定時間間隔的服務(wù)器的狀態(tài)值,包括服務(wù)器的CPU使用率,內(nèi)存使用,虛擬內(nèi)存交換情況,IO讀寫情況,本文給大家介紹了Linux使用vmstat監(jiān)控系統(tǒng)性能的示例方法,需要的朋友可以參考下2025-03-03
在Linux環(huán)境如何將python腳本打deb包
為方便傳輸和使用Python腳本,可以將其制作成deb包。本文詳細(xì)介紹了在uos系統(tǒng)下使用debian目錄和相關(guān)文件來定制和構(gòu)建deb包,涵蓋創(chuàng)建配置文件、修改文件、設(shè)置安裝和鏈接規(guī)則等步驟,并提供了打包命令。這樣可以簡化腳本的分發(fā)和安裝過程,使其更加便捷2024-09-09
Linux簡介及最常用命令(簡單易學(xué),但能解決95%以上的問題)
這篇文章主要介紹了Linux簡介及最常用命令(簡單易學(xué),但能解決95%以上的問題),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-08-08
Linux6.7卸載系統(tǒng)自帶的mysql-libs* crontab命令不能用了原因分析
這篇文章主要介紹了Linux6.7卸載系統(tǒng)自帶的mysql-libs* crontab命令不能用了原因分析及解決方法,非常不錯,需要的朋友參考下吧2016-12-12
CentOS7服務(wù)器環(huán)境下vsftpd安裝及配置方法
這篇文章主要介紹了CentOS7服務(wù)器環(huán)境下vsftpd安裝及配置方法,結(jié)合實例形式分析了CentOS7服務(wù)器環(huán)境下進行vsftpd安裝及配置的步驟與相關(guān)問題解決方法,需要的朋友可以參考下2018-03-03

