如何使用Nginx投放图片 [英] How to serve images with nginx

查看:45
本文介绍了如何使用Nginx投放图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对nginx完全陌生,要求我找到一种方法来服务根据缩放级别分开的地图图块.图像文件结构类似于〜/data/images/7/65/70.png ,其中7是缩放级别,65和70是lon-lat值.文件夹65包含许多文件,例如71.png,72.png等.

我已经正确安装了Nginx,并且可以收到 Welcome to nginx 消息.我已按照 http://nginx.org/zh-CN/docs/beginners_guide.html 中的说明进行操作,并创建了/data/www /data/images目录.我已将index.html文件放置在/data/www 下,并将图像平铺在/data/images 下.然后,我通过在http标记中添加以下行来修改配置文件:

 服务器{地点/{根/data/www;}位置/images/{根/数据;}} 

重新加载配置文件并在浏览器上输入localhost后,我既无法获取index.html文件,也无法查看图像.

我想做的是在输入以下内容时显示图像:

  http://localhost/1.0.0/basemap/7/65/70.png 

  • 7:表示第7级缩放级别的文件夹
  • 65:表示纬度的文件夹
  • 70.png:指示经度的文件(文件夹65包含许多png文件)

我想念什么?

解决方案

好,让我解释一下,您已经有一个本地主机,该主机是在名为 default 的文件中定义的,该文件是导致出现欢迎使用nginx"或某些内容,并且我相信您无法使用相同的 server_name 创建新服务器,让我们删除它并让您的本地主机仅提供那些图像,

  • 首先,我们需要从启用了的中删除 default 文件,如果您愿意,它仍将存在于 sites-available 中拿回来.(请注意,启用 sites的内部的所有文件只是来自 sites-available 内的文件的符号链接)
  • 我们在 sites-available 内创建一个新文件,并根据需要调用它,例如 images-app
  • images-app 文件中创建新服务器,我假设应用程序的根目录当然位于名为/data 的文件夹中您将其映射到自己的服务器结构.

     服务器{server_name localhost;根/数据;索引index.html;地点/{try_files $ uri = 404;}} 

  • 现在我们转到 sites-enabled 并启用我们在 sites-available

    内部创建的网站

      sudo ln -s/etc/nginx/sites-available/images-app/etc/nginx/sites-enabled/ 

  • 确保所有nginx配置正确

      sudo nginx -t 

  • 如果没有任何问题,我们可以继续并重新加载nginx设置

      sudo服务nginx重新加载 

I am completely new to nginx and I am asked to find a way to serve Map Tiles that are separated according to the zoom levels. The image file structure is like ~/data/images/7/65/70.png where 7 is the zoom level, 65 and 70 are the lon-lat values. The folder 65 contains many files such as 71.png, 72.png and etc.

I have installed Nginx properly and I can get Welcome to nginx message. I have followed the instructions in http://nginx.org/en/docs/beginners_guide.html and created the /data/www and /data/images directories. I have placed index.html file under /data/www and tile images under /data/images. Then I modified the configuration file by adding following lines in http tags:

server {
    location / {
        root /data/www;
    }

    location /images/ {
        root /data;
    }
}

After reloading the config file and entering localhost on the browser I can neither get the index.html file nor see the images.

What I am trying to do is to display the image when I enter something as:

http://localhost/1.0.0/basemap/7/65/70.png

  • 7: folder indicating 7th zoom level
  • 65: folder indicating the latitude
  • 70.png: file indicating the longitude (folder 65 includes many png files)

What am I missing?

解决方案

Ok, let me explain something, you already have a localhost server, which is defined inside a file called default that is the file that causes the "Welcome to nginx" or something to appear, and I believe you can't create a new server with the same server_name, let's remove that and make your localhost serve only those images,

  • First we need to delete the default file from sites-enabled , it will still exist inside sites-available if you ever want to get it back. ( note that all files inside sites-enabled are simply symlinks from the files inside sites-available )
  • We create a new file inside sites-available and call it whatever you want, images-app for example
  • create the new server inside the images-app file, I'll assume that the root of the app is inside a folder called /data of course you will map that to your own server structure.

    server {
        server_name localhost;
        root /data;
        index index.html;
        location / {
            try_files $uri =404;
        }
    }
    

  • now we go to sites-enabled and enable this site we created inside sites-available

    sudo ln -s /etc/nginx/sites-available/images-app /etc/nginx/sites-enabled/
    

  • make sure that all the nginx config are correct

    sudo nginx -t
    

  • If nothing is wrong we can go ahead and reload nginx settings

    sudo service nginx reload
    

这篇关于如何使用Nginx投放图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆