2、nginx提供静态内容-阅读官方文档

本文介绍了如何配置Nginx服务器以提供静态内容,如HTML页面和图片。通过编辑配置文件,设置server和location块,使得Nginx能够根据请求从不同的本地目录(/data/www和/data/images)提供文件。在完成配置后,需要重启Nginx以应用更改。通过访问localhost的特定路径,可以验证配置是否成功。
摘要由CSDN通过智能技术生成

官方网址:

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 an index.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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值