nginx动静分离demo
nginx动静分离demo
需求:当访问
http://118.31.3.255/www/a.html
时,访问静态资源html,当访问http://118.31.3.255/image/a.gif
时,访问gif图片1.首先在文件夹data下面分别创建两个文件夹
修改nginx配置文件
server
{
listen 80;
server_name 118.31.3.xxx;
#输入服务器ip时,直接访问/data/www/下面的index.html
location / {
root /data/www/;
index index.html index.htm;
}
# 输入www开头的访问html页面
location /www/ {
root /data/;
index index.html index.htm;
}
# 输入image开头的访问图片
location /image/ {
root /data/;
autoindex on;
}
}
3.效果
输入
http://118.31.3.255/www/a.html
时输入
http://118.31.3.255/image/a.gif
时输入
http://118.31.3.xxx
时,访问www文件夹下的index.html页面
还没有评论,来说两句吧...