Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Takis Bouyouris

    (@nevma)

    Hello, my friend,

    Nginx is the next thing I want to add to the plugin. It is not ready yet, but you could add something like this:

    location assets {
    }
    
    location wp-content/cache/adaptive-images {
    }
    
    location / {
        rewrite \.(?:jpe?g|gif|png)$ /wp-content/plugins/adaptive-images/adaptive-images/ai-main.php;
    }

    However, this is going to change in the near future!

    Do you think you could add this to your Nginx virtual host config file and tell me if it works?

    Thread Starter svkovalyov

    (@svkovalyov)

    It does not work for me because nginx works with Apache as the frontend, in this case it is not visible images. Nginx transmits Apache is not the correct $request_uri, and it turns out that $_SERVER[‘REQUEST_URI’] file ai-main.php sent as “/wp-content/plugins/adaptive-images/adaptive-images/ai-main.php” and must be in the form of “/wp-content/uploads/path-toimage”

    Thread Starter svkovalyov

    (@svkovalyov)

    The problem is solved by adding nginx:

    if ($request_uri ~ “/wp-content/uploads”) {
    set $adaptive 1;
    }
    if ($request_uri ~ “/wp-content/themes”) {
    set $adaptive 1;
    }
    if ($adaptive = 1) {
    rewrite \.(?:jpe?g|gif|png)$ /wp-content/plugins/adaptive-images/adaptive-images/ai-main.php?$request_uri last;
    }

    and ai-main.php file before parsing $_SERVER[‘REQUEST_URI’]:

    if (!empty($_SERVER[QUERY_STRING])){
    $_SERVER[‘REQUEST_URI’] = $_SERVER[QUERY_STRING];
    }

    Thread Starter svkovalyov

    (@svkovalyov)

    Wait, it’s not safe solution, because it allows an attacker to view the source files on the server using GET request. I think about how it can be solved in a safe way

    Plugin Author Takis Bouyouris

    (@nevma)

    You mean that the above code is not safe?

    (Thanks for all the testing and help with NginX, man!)

    Thread Starter svkovalyov

    (@svkovalyov)

    Not safe. This code allows any visitor can download any file from the server for example at https://example.com/wp-content/plugins/adaptive-images/adaptive-images/ai-main.php?/wp-config.php

    Plugin Author Takis Bouyouris

    (@nevma)

    Yes-yes, I understand. This is not the way to go. I was only asking if there was something not safe with my code or the Nginx configuration. It is clear now.

    Thread Starter svkovalyov

    (@svkovalyov)

    Problem solved. In the configuration nginx section location I deleted jpg|jpeg|gif|png and began to process Apache htaccess
    Before config location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
    After location ~* ^.+\.(svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
    I don’t know why I haven’t done this before:))

    Plugin Author Takis Bouyouris

    (@nevma)

    Great to hear this!

    I am not an Nginx expert, though! Does this config work in all Nginx setups or is it just for your setup (Nginx + Apanche in the frontend)?

    I am asking so that I can point other users to this answer in the future! ??

    Thread Starter svkovalyov

    (@svkovalyov)

    This solution is important when running of Nginx + Apanche in the frontend, when configured nginx proxied image location ~ * ^. + \. (Jpg | jpeg | gif | png | svg | js | css | mp3 | ogg | mpe? g | avi | zip | gz | bz2? | rar | swf) $ {

    Plugin Author Takis Bouyouris

    (@nevma)

    Could you write down the complete configuration that this setups requires and where one should put it? So that I can add it to the documentation!

    Thank you very much in advance.

    Thread Starter svkovalyov

    (@svkovalyov)

    It is necessary to remove jpg|jpeg|gif|png in the nginx.conf line location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
    and reload nginx

    Plugin Author Takis Bouyouris

    (@nevma)

    Oh, now I get it, you just need to remove these image types from the Nginx config file so that the requests are passed on to Apache, right?

    So, in this setup actually Nginx is in front and Apache in the back?

    Plugin Author Takis Bouyouris

    (@nevma)

    Just a quick note for users who read this post for versions 0.3 and above. The script:

    /wp-content/plugins/adaptive-images/adaptive-images/ai-main.php

    has now been renamed to:

    /wp-content/plugins/adaptive-images/adaptive-images-script.php

    Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Rules for nginx’ is closed to new replies.