Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Help me with Nginx
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help me with Nginx

Hi all, maybe this is stupid question. but please help me out.

i just running dev with php script that running remote upload images.
that will return image from my second domain.
currently it work with, ex:

_domain.com/img/title-id that actually request img from my another domain _example.com that accept custom header to get images, ex. real url is _example.com/img/id.jpg.

what i want right now is i need to bypass .jpg that actually not static file in server.
so currenly,

_domain.com/img/title-id work.

_domain.com/img/title-id.jpg not work.

how to make nginx rewrite properly on nginx server block, thanks.

Comments

  • oh additional info, it return 404 Not Found.

    Thanked by 1doghouch
  • Can you paste your actual config file so we can see clearly what you're trying to achieve?

    You may replace the domain name and IP addresses if you need privacy.

  • @UrDN currently its just default config, but i'll explain what im trying to achieve.

    here semiliar dev, _http://stackoverflow.com/questions/12629410/how-can-i-render-a-remote-image-with-php

    but i make with clean url, example:

    origin image file is on other server and domain, _example.com/img/123456.jpg

    and in my current server i have domain, ex: _domain.com that need serve images based on _example.com

    so i make clean url and everytime i request images with url.

    _domain.com/img/some-clean-image-title-123456.jpg is actually images from _example.com/img/123456.jpg and i dont have that image file in server. so 123456 is ID that i can dealing with my php code.

    its working without extension in url with _domain.com/img/some-clean-image-title-123456 because it pass as php and just add header that its look like image on header.

    the problem is i want clean url and add extension .jpg and nginx try to serve that url as static file that currently that file is not in my server.

    i want it bypass every request that based on img/ should pass that rewrite rules, and i dont have idea rewrite rules to make this happen.

  • I believe the regex used is not matching the DOT in the url
    Just copy paste the rule two times one with extension hard coded

  • andiklive said: its working without extension in url with _domain.com/img/some-clean-image-title-123456 because it pass as php and just add header that its look like image on header.

    the problem is i want clean url and add extension .jpg and nginx try to serve that url as static file that currently that file is not in my server.

    if I get this right you probably want to filter for the base-path /img and the extension .jpg and send every requests that matches to your php-engine. otherwise nginx will look for static files which cannot be found.

    so you just need rule like for .php but matching .jpg instead, right?

  • @noaman said:
    I believe the regex used is not matching the DOT in the url
    Just copy paste the rule two times one with extension hard coded

    yeah, that im trying to do. how to make that bypass rules

    @Falzo said:
    if I get this right you probably want to filter for the base-path /img and the extension .jpg and send every requests that matches to your php-engine. otherwise nginx will look for static files which cannot be found.

    so you just need rule like for .php but matching .jpg instead, right?

    definitely right, how to make that rules. im not familiar with nginx rewrite rules. is:

    location /img* \.(jpe?g|png|gif|ico)$ { .......... }

    or

    location /img \.(jpe?g|png|gif|ico)$ { .......... }

    so actually i dont what rules i should put on img location block. and for php-engine i use Laravel Framework. any idea how make this work.

  • First you have to tell that it's a regex. ~* for case-insensitive and ~ for case sensitive.

    I believe you are trying to achieve this:

    location ~* /img/.*.jpg$ {
    }
    
  • @UrDN said:
    First you have to tell that it's a regex. ~* for case-insensitive and ~ for case sensitive.

    I believe you are trying to achieve this:

    location ~* /img/.*.jpg$ {
    }
    

    its doesnt matter content, as long it can bypass the jpg.
    how about inside that block, its same as inside php?
    thanks

Sign In or Register to comment.