[ask] nginx handle file .jpg yg tidak exist

Discussion in 'Masalah Teknik dan Keamanan' started by sitsuit, 30 May 2014.

Thread Status:
Not open for further replies.
  1. sitsuit

    sitsuit Beginner 2.0

    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Halo semua,

    Bisakah nginx dikonfigurasi utk memforward request ke file .jpg yang tidak ada ke file .jpg lain.
    Misalkan :
    request ke anu.jpg, karena anu.jpg tidak ada, maka nginx akan memforward ke ga_ada.jpg.

    Saya pernah baca ttg 404 handler, tapi kebutuhan saya hanya untuk file .jpg.

    Thanks sebelumnya
     
  2. Nina Prasetyo

    Nina Prasetyo Expert 2.0

    Messages:
    970
    Likes Received:
    277
    Trophy Points:
    63
    Kalau di Apache sih bisa pakai rewrite .htaccess
    Kalau re-write-nya nginx saya ngga begitu faham... walaupun memang ada converter rewrite dari apache ke nginx.

    Mungkin bawah saya ada bisa bantu..
     
  3. Fuji Ahmad

    Fuji Ahmad Apprentice 2.0

    Messages:
    460
    Likes Received:
    61
    Trophy Points:
    28
    pake cara ini:

    Code:
           location ~*  \.(jpg)$ {
                    expires 1d;
                    access_log off;
                    log_not_found off;
                    error_page 404 = ga_ada.jpg;
                    }
    
     
    sitsuit and Nina Prasetyo like this.
  4. Fuji Ahmad

    Fuji Ahmad Apprentice 2.0

    Messages:
    460
    Likes Received:
    61
    Trophy Points:
    28
    kl ini settingan salah satu website klient saya

    Code:
           location ~*  \.(jpg|jpeg|png|gif|css|js|ico|swf|ttf|woff)$ {
                    expires 30d;
                    access_log off;
                    log_not_found off;
                    error_page 404 = 404.jpg;
                    }
    pastikan file 404.jpg itu eksis, kl gak ntar redirect loop
     
  5. Nina Prasetyo

    Nina Prasetyo Expert 2.0

    Messages:
    970
    Likes Received:
    277
    Trophy Points:
    63
    kalau pakai try_files $uri bisa juga ngga ya ?
     
  6. Fuji Ahmad

    Fuji Ahmad Apprentice 2.0

    Messages:
    460
    Likes Received:
    61
    Trophy Points:
    28
    kl yg itu blm nyobain, try_files biasa untuk global configuration.
    misalkan redirect permanent ke domain br, pake try_file,
    contohnya akses domainlama.com/hello-world.html akan diredirect ke domainbaru.com/hello-world.html
     
  7. Nina Prasetyo

    Nina Prasetyo Expert 2.0

    Messages:
    970
    Likes Received:
    277
    Trophy Points:
    63
    Oh gitu tho... baru faham.... thx Pak Fuji.
     
  8. Fuji Ahmad

    Fuji Ahmad Apprentice 2.0

    Messages:
    460
    Likes Received:
    61
    Trophy Points:
    28
    Nina Prasetyo likes this.
  9. Nina Prasetyo

    Nina Prasetyo Expert 2.0

    Messages:
    970
    Likes Received:
    277
    Trophy Points:
    63
    Siap Pak. Benar. try_files lebih komplit. Dan karena komplit, harus spesifik.
     
  10. sitsuit

    sitsuit Beginner 2.0

    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Wah, sip banget nih.
    Nanti malam dicoba deh.

    Thanks ya
     
Loading...
Thread Status:
Not open for further replies.

Share This Page

Loading...