官方网址:
Beginner’s Guidehttp://nginx.org/en/docs/beginners_guide.html#static
说明:
本人在windows中操作,路径写法和Linux会有不同
不写/data/www而是写D:/software/nginx-1.20.1/data/www
翻译部分:Serving Static Content
# An important web server task is serving out files (such as images or static HTML pages).
web服务器 的一个重要任务是提供文件(例如 照片或者静态html文件)
# You will implement an example where, depending on the request, files will be served from different local directories:
/data/www
(which may contain HTML files) and/data/images
(containing images).
接下来你将会实现一个实例,根据请求,从不同的本地目录中提供请求所需的文件
# This will require editing of the configuration file and setting up of a server block inside the http block with two location blocks.
这将要求你修改nginx配置文件,在http块中设置带有两个location块的sever块
人话:xx是路径匹配规则,根据自己的情况修改即可
http {
server {
location xx {}
location xx {}
}
}
# First, create the
/data/www
directory and put anindex.html
file with any text content into it and create the/data/images
directory and place some images in it.
首先,创建目录/data/www并在该目录放置一个含有任意内容的index.html文件,然后,创建目录/data/images并在该目录下放置一些图片。
/data/www