在Windows上使用nginx搭建图片服务器
1.下载nginx
nginx下载链接: nginx.
2,解压nginx
3. 打开nginx配置文件
路径为 nginx-1.18.0\conf\nginx.conf
4.修改文件
找到
location / {
root html;
index index.html index.htm;
}
复制一份到下面修改成以下配置
location /img/ {
alias D:/img/;
}
以D盘为例 存放图片的文件夹名称为:img
代码如下
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /img/ {
alias D:/img/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
5.启动nginx
如果加压后没有点击过nginx.exe,直接点击启动就行 ,如果点击过 打开当前文件夹的Powershell(Shift+鼠标右键)命令 .\nginx.exe -s reload,没有报错就说明启动成功,报错请到logs文件夹的errer.log查看日志
6.效果展示
把图片1.jpg 放入到D盘的img文件夹里面 看上面配置
location /img/ {
alias D:/img/;
}