nginx静态资源服务器怎么配置 |
您所在的位置:网站首页 › nginx访问静态资源配置 › nginx静态资源服务器怎么配置 |
进入nginx安装目录的conf目录下,修改nginx.conf文件,在一个server{}中添加 一个location 部分配置代码如下 root@ubuntu:/usr/local/nginx/conf# vi nginx.conf server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /image/ { root /usr/local/myimage/; autoindex on; } }登录后复制从上面的配置可以看出来 端口为80,server_name为localhost(写ip地址也可以) location /image/ { root /usr/local/myimage/; autoindex on; }登录后复制这个配置表示输入 localhost:80/image/ 时会访问本机的/usr/local/myimage/image/ 目录。所以要新建/usr/local/myimage/image/ 目录,同时还要在nginx安装目录的html目录中新建一个 与 location中 image同名的image目录,虽然该目录里面什么也没有,在/usr/local/my image/image/ 中我们放一张图片1.jpg上去,重启nginx服务,就可以通过 localhost:80/image/1.jpg访问了 root@ubuntu:/usr/local/nginx/html# mkdir image root@ubuntu:/usr/local/nginx/html# mkdir /usr/local/myimage/image #放一张照片上去# root@ubuntu:/usr/local/nginx/html# cd /usr/local/myimage/image root@ubuntu:/usr/local/myimage/image# ls 1.jpg root@ubuntu:/usr/local/myimage/image#登录后复制重启 nginx root@ubuntu:/usr/local/nginx/sbin# ./nginx -s reload root@ubuntu:/usr/local/nginx/sbin#登录后复制打开浏览器 输入 server_name:80/image/1.jpg 就可以访问该静态图片了如下图 以上就是nginx静态资源服务器怎么配置的详细内容,更多请关注php中文网其它相关文章! |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |