在做一些小項目和學習項目過程中,學習了通過 nginx 和 FTP 搭建小型文件服務器,記錄下:
1.環境
- 電腦:acer
- 操作系統:windows 10
- ftp服務器
2.下載 nginx, 通過雙擊圖標 nginx.exe 或則啟動 cmd 命令行啟動
3.運行后,瀏覽器訪問 localhost:80,進入主頁,完成
4.無法訪問時,可能是 80 端口被占用,可以 kill 掉這個任務,但可能是 IIS 服務每次強制更新后就會監聽 80 端口
5.這時候,找到 ‘打開或關閉窗口功能’ ,將勾選 Internet Information Services 去掉,估計能解決吧
6.在准備好一個FTP服務器后,可搭建一個簡單的文件服務器,文件設置:
image.cat.com.conf : (創建該文件在 nginx/conf/vhost 文件下,方便 nginx.conf 文件中導入)
E:\ftpfile 為 ftpServer 的文件目錄
server { listen 80; autoindex off; server_name image.cat.com; access_log c:/access.log combined; index index.html index.htm index.jsp index.php; #error_page 404 /404.html; if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; } location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* { deny all; } location / { root E:\ftpfile; add_header Access-Control-Allow-Origin *; } }
hosts:(該文件在本機電腦下的路徑為 C:\Windows\System32\drivers\etc)
127.0.0.1 image.cat.com
nginx.conf:
include vhost/*.conf;
7.這時,瀏覽器訪問 image.cat.com/10.jpg, 完成
8.如果訪問提示 403 Forbidden,可以檢查下 FTP 服務器文件目錄存放的位置!