Linux如何搭建文件服務(wù)器
搭建簡(jiǎn)單文件服務(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"> #用于針對(duì)指定目錄(在這里是/var/www)設(shè)置訪(fǎng)問(wèn)控制規(guī)則的開(kāi)始標(biāo)簽。以下的配置將應(yīng)用于/var/www目錄及其子目錄。
AllowOverride None
# Allow open access:
Require all granted #表示允許所有人訪(fǎng)問(wèn)/var/www目錄及其子目錄,沒(méi)有訪(fǎng)問(wèn)限制
</Directory>
Listen 80 #默認(rèn)的監(jiān)聽(tīng)端口,修改80后則需要指定IP:端口進(jìn)行訪(fǎng)問(wèn)注釋/etc/httpd/conf.d/welcome.conf文件下的此內(nèi)容,不然就會(huì)返回禁止訪(fǎng)問(wèn)報(bào)錯(cuò)
#<LocationMatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#</LocationMatch>
文件服務(wù)器下創(chuàng)建測(cè)試文件
[root@localhost ~]# echo hello > /var/www/html/test.txt
啟動(dòng)httpd并設(shè)置開(kāi)機(jī)自啟
[root@localhost ~]# systemctl enable --now httpd
訪(fǎng)問(wèn)界面如下

此時(shí)的文件服務(wù)器還不能下載,點(diǎn)擊后會(huì)打開(kāi)該文件

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

完善文件服務(wù)器的瀏覽器界面,在http.conf的Directory標(biāo)簽中添加
Options +Indexes:?jiǎn)⒂媚夸浰饕?,允許顯示目錄內(nèi)容。
IndexOptions FancyIndexing:?jiǎn)⒂妹阑哪夸浰饕愿纳颇夸泝?nèi)容的可讀性。
IndexOptions NameWidth=:允許文件名列寬度自動(dòng)調(diào)整以適應(yīng)不同文件名的長(zhǎng)度。
IndexOptions DescriptionWidth=:允許描述列寬度自動(dòng)調(diào)整以適應(yīng)不同文件描述的長(zhǎ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;# 顯示文件時(shí)間
root /opt; #/opt表示你要共享的文件服務(wù)器根目錄啟動(dòng)nginx,并開(kāi)機(jī)自啟
[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訪(fǎng)問(wèn),如果要指定端口,修改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訪(fǎng)問(wèn)

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

總的來(lái)說(shuō)ubuntu搭建更加簡(jiǎn)單一些,做的配置也不多
到此這篇關(guān)于Linux搭建文件服務(wù)器的文章就介紹到這了,更多相關(guān)Linux文件服務(wù)器搭建內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Apache中如何設(shè)置默認(rèn)首頁(yè)具體該怎么操作
這篇文章主要介紹了Apache中設(shè)置默認(rèn)首頁(yè)的方法,需要的朋友可以參考下2014-02-02
阿里云linux服務(wù)器上使用iptables設(shè)置安全策略的方法
這篇文章主要介紹了阿里云linux服務(wù)器上使用iptables設(shè)置安全策略的方法,需要的朋友可以參考下2016-10-10
Linux、CentOS下安裝zip與unzip指令功能(服務(wù)器)
這篇文章主要介紹了Linux、CentOS下安裝zip與unzip指令的操作方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-11-11
Ubuntu18.04一次性升級(jí)Python所有庫(kù)的方法步驟
這篇文章主要介紹了Ubuntu18.04一次性升級(jí)Python所有庫(kù)的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
Linux使用fdisk進(jìn)行磁盤(pán)的相關(guān)操作
fdisk?命令是?Linux?中用于管理磁盤(pán)分區(qū)的強(qiáng)大文本實(shí)用程序,這篇文章主要為大家詳細(xì)介紹了如何使用fdisk進(jìn)行磁盤(pán)的相關(guān)操作,需要的可以了解下2025-01-01
linux 查看文件系統(tǒng)類(lèi)型實(shí)例方法
在本篇文章里小編給大家整理的是一篇關(guān)于linux 查看文件系統(tǒng)類(lèi)型實(shí)例方法,對(duì)此有興趣的朋友們可以學(xué)習(xí)參考下。2021-02-02

