最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Linux如何搭建文件服務(wù)器

 更新時(shí)間:2023年10月20日 09:47:17   作者:huhy~  
這篇文章主要介紹了Linux如何搭建文件服務(wù)器,包括基于centos7.9搭建http文件服務(wù)器,基于centos7.9搭建nginx文件服務(wù)器以及基于ubuntu2204搭建http文件服務(wù)器,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧

搭建簡(jiǎn)單文件服務(wù)器

IP環(huán)境
192.168.200.100VMware17

基于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.200VMware17

安裝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)文章

最新評(píng)論

依兰县| 金溪县| 子长县| 渭南市| 环江| 兰溪市| 龙里县| 双城市| 邳州市| 黑龙江省| 辉县市| 驻马店市| 察雅县| 深泽县| 浑源县| 亚东县| 南华县| 大关县| 黎川县| 鹿泉市| 隆林| 泾阳县| 衡山县| 阿城市| 慈溪市| 公主岭市| 紫阳县| 长寿区| 建德市| 金川县| 临猗县| 金堂县| 安福县| 麻阳| 澄迈县| 孝昌县| 杭锦后旗| 美姑县| 正定县| 丰镇市| 南岸区|