Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image nginx、别名和位置_Image_Nginx_Location_Alias - Fatal编程技术网

Image nginx、别名和位置

Image nginx、别名和位置,image,nginx,location,alias,Image,Nginx,Location,Alias,我在nginx中有一个配置文件,如 server { root /var/www/releaser/site/web/; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php5-fpm.sock; } location ^~ /images/ { alias /var/www/releaser/s

我在nginx中有一个配置文件,如

server {
    root /var/www/releaser/site/web/;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ^~ /images/ {
        alias /var/www/releaser/site/web/img/;
    }

    # Media: images, icons, video, audio, HTC
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
    }

    include snippets/nginx-basics.conf;

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

    server_name site.test;
}
因此,当我这样做时(图像的额外标题丢失):

但是,如果我这样做(包括图像的额外标题):

如何在不将额外标题的副本放入alias的location部分的情况下修复此问题


非常感谢

一种解决方案是将
alias
指令替换为
rewrite
指令:

location ^~ /images/ {
  rewrite ^/images(.*)$ /img$1;
}

它就像一个符咒。你能告诉我什么时候使用alias好,什么时候重写合适吗?@kai我发现,
alias
的范围非常有限。您的示例是教科书式的,除了额外的头约束。
$ curl -I site.test/img/one.jpg
HTTP/1.1 200 OK
Server: nginx/1.9.3 (Ubuntu)
Date: Tue, 10 Nov 2015 05:29:36 GMT
Content-Type: image/jpeg
Content-Length: 185547
Last-Modified: Fri, 24 Jul 2015 22:12:20 GMT
Connection: keep-alive
Expires: Thu, 10 Dec 2015 05:29:36 GMT
Cache-Control: max-age=2592000
Cache-Control: public
Accept-Ranges: bytes
location ^~ /images/ {
  rewrite ^/images(.*)$ /img$1;
}