静态文件
即实现nginx代理指向静态文件,动静分离
主要配置如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location /images {
root /Users/jun/data;
}
location / {
root /Users/jun/data/www;
index index.html index.htm;
}
}
include servers/*;
}
http://localhost/images/jie.png的请求会匹配上面的location,返回本地/Users/jun/data/images/jie.png的图片,
http://localhost/ 的请求会匹配到下面的location,然后返回本地/Users/jun/data/www/下面的index.html文件。
开始一直搞不懂文件匹配规则,其实就是匹配到相应的location后,把请求url拼接到root的参数后去本地文件系统中查找,如刚才http://localhost/请求,返回/Users/jun/data + /即/Users/jun/data/下的index.html(缺省文件),对于http://localhost/images/jie.png请求 就返回/Users/jun/data/www + /images/jie.png 即服务器本地/Users/jun/data/images/jie.png的图片。

本文介绍了如何使用Nginx代理静态文件实现动静分离,详细讲解了配置过程,包括如何匹配请求并返回本地文件。此外,还讨论了Nginx的负载均衡配置,以及如何进行HTTPS反向代理和在同一台机器上部署多个webapp到不同端口的策略。
最低0.47元/天 解锁文章
862

被折叠的 条评论
为什么被折叠?



