Welcome! Log In Create A New Profile

Advanced

Serve Image files only

Posted by nginx_user10 
Serve Image files only
April 01, 2018 09:30PM
I am trying to serve images files only in this location block.

location /image \.(png|jpg)
{
alias /site/;
}

But I keep receiving errors. What is the correct way to serve only png and jpg matching /images.
Re: Serve Image files only
April 02, 2018 08:49AM
nginx_user10 Wrote:
-------------------------------------------------------
> I am trying to serve images files only in this location block.
>
> location /image \.(png|jpg)
> {
> alias /site/;
> }
>
> But I keep receiving errors. What is the correct way to serve only png
> and jpg matching /images.


*********************** update *************************

This location block works if I put a redirect in the block. But if I try to show the image via <img src or make a link clickable nothing works.

location ~* /images2/.+\.(png|jpg)$
{
}

The error logs says the following

GET /images2/flowers/type/T.png/ HTTP/1.1" 404 209
Re: Serve Image files only
April 02, 2018 10:14AM
nginx_user10 Wrote:
-------------------------------------------------------
> nginx_user10 Wrote:
> -------------------------------------------------------
> > I am trying to serve images files only in this location block.
> >
> > location /image \.(png|jpg)
> > {
> > alias /site/;
> > }
> >
> > But I keep receiving errors. What is the correct way to serve only
> png
> > and jpg matching /images.
>
>
> *********************** update *************************
>
> This location block works if I put a redirect in the block. But if I
> try to show the image via <img src or make a link clickable nothing
> works.
>
> location ~* /images2/.+\.(png|jpg)$
> {
> }
>
> The error logs says the following
>
> GET /images2/flowers/type/T.png/ HTTP/1.1" 404 209

*******************************solved*****************************

location ~ ^/images/(.+\.(?:gif|jpe?g|png))$
{
include /etc/nginx/mime.types;
alias /site/$1;

}

Not certain but I needed to add $1 to the end and changed the regex a little.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 259
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready