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