Nginx 配静态资源

来源:互联网 发布:电脑连不上网络错误711 编辑:程序博客网 时间:2024/05/29 04:14
  • 废话不多说,直接上重点。
  • 首先我们需要有一个Nginx(http://nginx.org/)

下载完成以后,进入Nginx下的cof目录,然后打开nginx.conf(修改之前记得备份

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 /file/ {            root   E:/imges;            autoindex on;        }

找到Server可以自己另写,也可以直接再Server中增加,为了精华,我这就直接写location了。
这种访问方式为,访问localhost:80/file,会自己去到E:/imges下面寻找。

不要把Image当作代替Root的路径,可以理解为,在root后面追加的一个文件名/

*假如你E:/imges/file/下面有一个a.jpg,name你的访问路径为:
localhost:80/file/a.jpg***