本文来说下Nginx作为静态服务器几个问题
概述
在实际开发中经常会遇到静态服务器,通常会提供一个上传的功能,其他应用如果需要静态资源就从该静态服务器中获取。
nginx的下载地址:http://nginx.org/en/download.html
Nginx怎么处理请求的
nginx接收一个请求后,首先由listen和server_name指令匹配server模块,再匹配server模块里的location,location就是实际地址。
实战测试
监听了localhost下面的2021端口,并且修改根目录为D:/supervision/pre/upload
nginx.conf文件配置信息
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 2021;
server_name localhost;
location / {
root D:/supervision/pre/upload;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
在D:/supervision/pre/upload文件夹中放了一张图片来进行测试
在实际开发中,比如文件上传等功能,可以把文件,图片等资源上传到一个指定的文件夹中,然后可以是nginx作为图片服务器,到指定的文件夹中去拿。
本文小结
本文介绍了nginx作为静态图片服务的使用。也是在开发中一个常用的功能。