Nginx 服務器的一個主要任務是提供靜態HTML頁面、圖像或文件訪問。
根據請求的不同,文件將從不同的本地目錄提供。
- /http/www 包含HTML文件
- /http/data1/images 包含圖像
- /http/data2/file 包含文件
目錄樹:
http/ ├── data1 │ └── images │ ├── 1.jpg │ └── 2.jpg ├── data2 │ └── file │ ├── 1.txt │ └── 1.zip └── www ├── 50x.html └── index.html |
配置文件:
server { listen 80; server_name 127.0.0.1; location / { root /http/www ; index index.html index.htm; } location /data1/ { root /http ; } location /data2/ { root /http ; } error_page 500 502 503 504 /50x .html; location = /50x .html { root /http/www ; } } |
可以訪問一下鏈接查看效果:
HTML靜態文件:http://192.168.1.200/
圖像瀏覽:http://192.168.1.200/data1/images/1.jpg
文件下載:http://192.168.1.200/data2/file/1.zip