Nginx提供本地图像

时间:2019-05-24 08:47:29

标签: nginx nginx-config

尝试使用nginx加载图像时出现错误。

我有一个像这样的文件夹

-rwxrwxrwx 1 www-data root  7945 May 23 09:44 tq__5831b8d9.jpg
-rwxrwxrwx 1 www-data root  6691 May 23 09:44 wtl__2520fe4c.jpg
-rwxrwxrwx 1 www-data root  4135 May 23 09:44 wtl__6c002c5c.jpg
root@vcas:/www/data/media# pwd
/www/data/media

我正在尝试使用nginx加载图像,这是我的nginx配置文件。

user www-data;
    worker_processes 1;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

    http {

        log_format compression '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $upstream_addr '
            '"$http_referer" "$http_user_agent" "$gzip_ratio"';
        sendfile off;


        # what times to include
        include       /etc/nginx/mime.types;
        # what is the default one
        default_type  application/octet-stream;
        gzip on;
        gzip_proxied any;
        gzip_types text/plain text/xml text/css application/x-javascript;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";


        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        server {
            listen 8082 default_server;
            access_log /var/log/nginx/access.log compression;


            location / {

            root /var/www/html/content/www/data;
            # First attempt to serve request as file, then
            # as directory, then fall back to redirecting to index.html
            try_files $uri $uri/ /index.html;
            # Media: images, icons, video, audio, HTC
            location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
            sendfile off;
            expires 1s;
            access_log on;
            add_header Cache-Control "public";
            }

            # Javascript and CSS files
            location ~* \.(?:css|js)$ {
                try_files $uri =404;
                expires -1;
                access_log off;
                add_header Cache-Control no-cache;
            }
            }

            location /poi_images {
             root /www/data/media;

            # First attempt to serve request as file, then
            # as directory, then fall back to redirecting to index.html
            # Media: images, icons, video, audio, HTC
            location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
            try_files $uri $uri/ /poi_images/default.jpg;
            sendfile on;
            expires 1M;
            access_log off;
            add_header Cache-Control "public";
            }
            }



            # Any route containing a file extension (e.g. /devicesfile.js)
            location ~ ^.+\..+$ {
                try_files $uri =404;
            }

            location /api {
                proxy_pass         http://localhost:3000;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $server_name;
                proxy_http_version 1.1;
                proxy_set_header Connection "";
            }

        }
    }

每次尝试加载时都会出错 /poi_images/wtl__6c002c5c.jpg

错误日志为

2019/05/24 08:27:03 [error] 24392#0: *1 rewrite or internal redirection cycle while internally redirecting to "/poi_images/default.jpg", client: 192.168.10.172, server: , request: "GET /poi_images/wtl__6c002c5c.jpg HTTP/1.1", host: "192.168.10.2:8082"

如果我在某处的配置错误,有人可以帮我吗?

谢谢

0 个答案:

没有答案