文件服務器搭建
文件服務器有四個選擇:
- httpd(apache)
穩定,使用廣泛,服務器一般自帶,對于開發人員來說強烈推薦。
- nginx
穩定高效,使用廣泛,linux命令可直接下載,對于開發人員來說強烈推薦。
- miniserve
簡單易用,可直接下載安裝包使用,跨平臺。
- gohttpserver
簡單易用,可直接下載安裝包使用,跨平臺,還支持上傳功能。
gohttpserver安裝使用
這里推薦使用gohttpserver。二進制包請點擊這里下載.
這里以amd64為例,使用如下命令下載二進制包:
(base) ┌──(dys?kali)-[~/tools]
└─$wget https://github.com/codeskyblue/gohttpserver/releases/download/1.1.4/gohttpserver_1.1.4_linux_amd64.tar.gz
(base) ┌──(dys?kali)-[~/tools]
└─$ tar -xvf gohttpserver_1.1.4_linux_amd64.tar.gz
LICENSE
README.md
gohttpserver
解壓完成后使用如下命令運行:
(base) ┌──(dys?kali)-[~/tools]
└─$ ./gohttpserver -r /video --port 8096 --upload
2023/12/05 19:49:33 httpstaticserver.go:75: root path: /video/
2023/12/05 19:49:33 main.go:185: plistproxy: "https://plistproxy.herokuapp.com/plist"
2023/12/05 19:49:33 main.go:244: listening on ":8096", local address http://192.168.0.110:8096
2023/12/05 19:49:34 httpstaticserver.go:90: Started making search index
2023/12/05 19:50:07 httpstaticserver.go:92: Completed search index in 32.823624317s
2023/12/05 19:50:39 httpstaticserver.go:145: GET /video
2023/12/05 19:50:39 main.go:57: 192.168.0.110 - GET 200 /
2023/12/05 19:50:46 httpstaticserver.go:145: GET -/user /video/-/user
2023/12/05 19:50:46 main.go:57: 192.168.0.110 - GET 404 /-/user
2023/12/05 19:50:46 main.go:57: 192.168.0.110 - GET 200 /?json=true&_=1701777380703
2023/12/05 19:50:56 main.go:57: 192.168.0.110 - GET 200 /video?json=true&_=1701777380704
為了保證gohttpserver開機可用或者意外停止后仍然可用,需要將gohttpserver配置成服務。
httpd配置
使用如下命令安裝apache,
(base) ┌──(dys?kali)-[~/tools]
└─$ sudo apt install apache2
然后啟動apache2,
(base) ┌──(dys?kali)-[~/tools]
└─$ sudo systemctl status apache2.service
○ apache2.service - The Apache HTTP ServerLoaded: loaded (/lib/systemd/system/apache2.service; disabled; preset: disabled)Active: inactive (dead)Docs: https://httpd.apache.org/docs/2.4/(base) ┌──(dys?kali)-[~/tools]
└─$ sudo systemctl start apache2.service
修改ports.conf,將監聽端口改為自己想要的然后再重啟服務器。
(base) ┌──(dys?kali)-[~/tools]
└─$ sudo vim /etc/apache2/ports.conf (base) ┌──(dys?kali)-[~/tools]
└─$ sudo systemctl restart apache2.service
nginx配置
若nginx未下載,則需要先下載nginx。
apt install nginx
下載完成后,需要修改nginx配置:
vim /etc/nginx/nginx.conf
然后在http節點添加如下內容:
autoindex on; #開啟索引功能autoindex_exact_size off; # 關閉計算文件確切大小(單位bytes),只顯示大概大小(單位kb、mb、gb)autoindex_localtime on; # 顯示本機時間而非 GMT 時間charset utf-8; # 避免中文亂碼server {listen 8080; #監聽端口號server_name 192.168.0.110;root /video; # 共享的文件目錄location / {}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}
然后啟動nginx,
systemctl restart nginx