Title: Rules for nginx
Last modified: August 30, 2016

---

# Rules for nginx

 *  Resolved [svkovalyov](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/)
 * I have a server running nginx and plug-in does not work because nginx does not
   read rules htaccess, what solution?
 * [https://wordpress.org/plugins/adaptive-images/](https://wordpress.org/plugins/adaptive-images/)

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [Takis Bouyouris](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230703)
 * 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](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230734)
 * 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](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230744)
 * 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](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230748)
 * 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](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230755)
 * You mean that the above code is not safe?
 * (Thanks for all the testing and help with NginX, man!)
 *  Thread Starter [svkovalyov](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230756)
 * Not safe. This code allows any visitor can download any file from the server 
   for example at [http://example.com/wp-content/plugins/adaptive-images/adaptive-images/ai-main.php?/wp-config.php](http://example.com/wp-content/plugins/adaptive-images/adaptive-images/ai-main.php?/wp-config.php)
 *  Plugin Author [Takis Bouyouris](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230783)
 * 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](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230809)
 * 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](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230813)
 * 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](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230898)
 * 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](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230899)
 * 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](https://wordpress.org/support/users/svkovalyov/)
 * (@svkovalyov)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230904)
 * 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](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230905)
 * 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](https://wordpress.org/support/users/nevma/)
 * (@nevma)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230969)
 * 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.

 * ![](https://ps.w.org/adaptive-images/assets/icon-256x256.png?rev=1138642)
 * [Adaptive Images for WordPress](https://wordpress.org/plugins/adaptive-images/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/adaptive-images/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/adaptive-images/)
 * [Active Topics](https://wordpress.org/support/plugin/adaptive-images/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/adaptive-images/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/adaptive-images/reviews/)

 * 14 replies
 * 2 participants
 * Last reply from: [Takis Bouyouris](https://wordpress.org/support/users/nevma/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/rules-for-nginx/#post-6230969)
 * Status: resolved