Rules for nginx
-
I have a server running nginx and plug-in does not work because nginx does not read rules htaccess, what solution?
-
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?
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”
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];
}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
You mean that the above code is not safe?
(Thanks for all the testing and help with NginX, man!)
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
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.
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:))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! 🙂
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) $ {
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.
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 nginxOh, 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?
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!
The topic ‘Rules for nginx’ is closed to new replies.