WordPress.org

Forums

ByREV WP-PICShield
Can't work under nginx (22 posts)

  1. Chris
    Member
    Posted 2 years ago #

    I use nginx and the .htaccess can't work, then the plugin don't work

    http://wordpress.org/extend/plugins/byrev-wp-picshield-hotlink-defence/

  2. Emilian Robert Vicol
    Member
    Plugin Author

    Posted 2 years ago #

    No, no work, my apologies but for now it is not compatible.

    For the present is no time to write the code to be compatible with nginx, maybe in the future !!!

  3. shakauy
    Member
    Posted 2 years ago #

    I've made it work with Nginx + PHP-FPM daemon. In some days I will release the code for free. Stay tuned.

  4. Emilian Robert Vicol
    Member
    Plugin Author

    Posted 2 years ago #

    I'm glad you solved the problem and that you found a solution !
    _______
    I do not use nginx, so I do not really like to make changes until testing.
    But, I see there are already public php scripts for apache2nginx
    https://github.com/mow/apache2nginx/blob/master/rew.phps
    Not tested so , I do not know how good the code is !

    ... let the world be an open and free, competition is bad for human and good for corporations that rule the world!

    Cheers :-))

  5. Chris
    Member
    Posted 2 years ago #

    Wow, that's awesome!

    Hope you can release the code ASAP!

  6. Emilian Robert Vicol
    Member
    Plugin Author

    Posted 2 years ago #

    These days I will install winginx and to test code to solve the problem, that unless @shakauy will provide solution founded by him ;)

  7. shakauy
    Member
    Posted 2 years ago #

    This is the code we used in our site, placed inside the "server" block configuration. Hope it helps to make a new release of this great plugin with Nginx configuration supported by default.

    location ~* \.(gif|jpg|jpeg|png)$ {
    valid_referers none blocked mysite.org *.mysite.org pinterest.com tumblr.com facebook.com plus.google twitter.com;

    if ($http_user_agent ~* !(googlebot|msnbot|baiduspider|slurp|webcrawler|teoma|photon|facebookexternalhit|pinterest|feedfetcher|photon|smush\.it|akamai|cloudfront|netdna|bitgravity|maxcdn|edgecast|limelight)) {
    return 418;
    }

    if ($invalid_referer) {
    return 418;
    }
    }
    }

    error_page 418 = @hotlink;

    location @hotlink {
    try_files /img/~hotlink-cache$uri /byrev-wp-picshield2.php?key=cm78-A3xv&src=$uri;
    }

  8. Chris
    Member
    Posted 2 years ago #

    @shakauy

    I tried it, but it seems that the code can't work

    location @hotlink {
    try_files /~hotlink-cache$uri /byrev-wp-picshield.php?key=awe0-oEH5&src=$uri;
    }

    Have you changed the byrev-wp-picshield2.php ??

  9. Emilian Robert Vicol
    Member
    Plugin Author

    Posted 2 years ago #

    Hi to all,

    I have too many projects and i did not have time for wp-picshield plugin (for the moment), but if I have time, the next a week I will try solving with nginx!

  10. shakauy
    Member
    Posted 2 years ago #

    Here is my byrev-wp-picshield2.php file:

    <?php
    define('_GTFO_KEY','cm78-A3xv');

    if (!array_key_exists('key', $_GET) OR ($_GET['key'] != _GTFO_KEY) ){
    header('HTTP/1.0 401 Unauthorized');
    echo 'Unauthorized!';
    die(401);
    }

    define('_WATERMARK_ENABLED', true);
    define('_REDIRECT_DIRECT_LINK_IMAGES_FROM_GOOGLE', true);
    define('_HOTLINK_CACHE_FOLDER', 'img/~hotlink-cache');
    define('_IMAGE_SOURCE_TRANSPARENCY', 65);
    define('_BLEND_BAR_WATERMARK', true);
    define('_BLEND_BAR_OPACITY', 25);
    define('_WRITE_HOST_SOURCE', false);
    define('_WATERMARK_POSITION', 0);
    define('_WRITE_CREDIT_PLUGIN', false);
    define('_MAXIMUM_MEGAPIXELS_SIZE', 3);
    define('_WATERMARK_PNG_FILE', 'watermark.png');
    define('_SEND_HOTLINK_GTFO_HEADER_SIGNATURE', false);
    define('_WRITE_TIME_CACHED_OVER_IMAGE', false);
    define('_PRINT_QR_HOST', false);
    define('_LOG_REFERER_AND_TARGET_IMG', false);
    define('_LOG_REFERER_TABLE', '** disabled **');
    define('_WATER_MARK_PASS_THROUGH', true);
    define('_WATER_MARK_REDIRECT_302_MODE', false);
    define('_WP_PICSHIELD_VERSION', '1.8.9 K2');
    define('_WP_PICSHIELD_FORCE_WATERMARK', isset($_GET['fw']));
    define('_WP_PICSHIELD_FORCE_DEBUG', isset($_GET['fd']));

    $image = ltrim(strip_tags( $_GET['src'] ), '/');

    if (_SEND_HOTLINK_GTFO_HEADER_SIGNATURE) {
    header('X-Protect: ByREV WP-PICShield , HOTLINK Defence');
    }

    #~~~~ headers = watermarked file NOT cache
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

    #~~~~ REDIRECT DIRECT LINK IMAGES with GOOGLE IMAGES REFERRER
    if (_REDIRECT_DIRECT_LINK_IMAGES_FROM_GOOGLE) :
    if (array_key_exists('HTTP_REFERER', $_SERVER)) {
    $url = $_SERVER['HTTP_REFERER'];
    $query = parse_url ($url, PHP_URL_QUERY);
    $host = parse_url ($url, PHP_URL_HOST);

    if (strstr ($query, 'q=') && strstr ($host, 'google.')) {
    require_once('byrev-wp-image2url.php');
    }

    }
    endif;

    #~~~~ if watermak is disabled
    function img_get_mime_type($file)
    {
    $mime_types = array(
    "gif"=>"image/gif",
    "png"=>"image/png",
    "jpeg"=>"image/jpg",
    "jpg"=>"image/jpg",
    );
    $file_exp = explode('.',$file);
    $extension = strtolower(end($file_exp));

    if (array_key_exists($extension, $mime_types)) {
    return $mime_types[$extension];
    }
    return "application/force-download";
    }

    if (!_WATERMARK_ENABLED) {
    $mime = img_get_mime_type($image);
    header('Content-type: '.$mime);
    fpassthru(fopen($image, 'rb'));
    exit();
    }

    #~~~~
    $dir = dirname(__FILE__);
    $watermarked = $dir.'/'._HOTLINK_CACHE_FOLDER.$image;

    #~~ create WATERMARK cache folders if not exists;
    $watermark_folder = dirname($watermarked);
    if(!is_dir($watermark_folder)) {
    mkdir($watermark_folder, 0777, true);
    }

    function byrev_image_type_to_extension($imagetype) {
    if(empty($imagetype)) return false;
    switch($imagetype) {
    case IMAGETYPE_GIF : return 'gif';
    case IMAGETYPE_JPEG : return 'jpeg';
    case IMAGETYPE_PNG : return 'png';
    case IMAGETYPE_SWF : return 'swf';
    case IMAGETYPE_PSD : return 'psd';
    case IMAGETYPE_BMP : return 'bmp';
    case IMAGETYPE_TIFF_II : return 'tiff';
    case IMAGETYPE_TIFF_MM : return 'tiff';
    case IMAGETYPE_JPC : return 'jpc';
    case IMAGETYPE_JP2 : return 'jp2';
    case IMAGETYPE_JPX : return 'jpf';
    case IMAGETYPE_JB2 : return 'jb2';
    case IMAGETYPE_SWC : return 'swc';
    case IMAGETYPE_IFF : return 'aiff';
    case IMAGETYPE_WBMP : return 'wbmp';
    case IMAGETYPE_XBM : return 'xbm';
    default : return false;
    }
    }

    #~~ if file exist, is serverd from disk, else is generated only once;
    if(file_exists($image)&& !file_exists($watermarked)){
    #~~~ image type
    $image_size = getimagesize($image);

    $image_mime = $image_size['mime'];

    $image_type = $image_size[2];
    $image_extension = byrev_image_type_to_extension($image_type);
    $imagecreatefrom = 'imagecreatefrom'.$image_extension;
    if (!function_exists($imagecreatefrom)) {
    header("Content-type: {$image_mime}");
    fpassthru(fopen($image, 'rb'));
    exit;
    }

    $sizex = $image_size[0];
    $sizey = $image_size[1];

    #~~ file si to big, may not be enough memory ... / exit
    $max_size = _MAXIMUM_MEGAPIXELS_SIZE * 1048576;
    if (($sizex*$sizey) > $max_size) {
    header("Content-type: {$image_mime}");
    fpassthru(fopen($image, 'rb'));
    exit;
    }

    //~~~ create images;
    $photo = $imagecreatefrom($image);
    $watermark = imagecreatefrompng(_WATERMARK_PNG_FILE);
    //imagealphablending($photo, true);

    $w = imagesx($watermark);
    $h = imagesy($watermark);

    //$sizex = imagesx($photo);
    //$sizey = imagesy($photo);

    $percent = $sizex / (($w>$h)?$w:$h);
    $nw = intval($w*$percent);
    $nh = intval($h*$percent);

    switch (_WATERMARK_POSITION) {
    case 0: $_watermark_ypos = 10; break;
    case 1: $_watermark_ypos = round( ($sizey/2) - ($nh/2) ) ; break;
    case 2: $_watermark_ypos = $sizey - $nh - 40; break;
    }

    #~~~ set original image source opacity
    $opacity_img = imagecreatetruecolor($sizex, $sizey);
    imagecopymerge($photo, $opacity_img, 0, 0, 0, 0, $sizex, $sizey, _IMAGE_SOURCE_TRANSPARENCY);

    #~~~ set higher opacity band
    if (_BLEND_BAR_WATERMARK) :
    $opacity_img = imagecreatetruecolor($nw, $nh);
    imagecopymerge($photo, $opacity_img, 0, $_watermark_ypos, 0, 0, $nw, $nh, _BLEND_BAR_OPACITY);
    endif;
    imagedestroy($opacity_img);

    #~~~ resize watermak with great deal of clarity
    $image_p = imagecreatetruecolor($nw, $nh);
    ImageAlphaBlending($image_p,false);
    ImageSaveAlpha($image_p,true);
    imagecopyresampled($image_p, $watermark, 0, 0, 0, 0, $nw, $nh, $w, $h);
    imagedestroy($watermark);

    #~~~ put watermak over image source
    imagecopy($photo, $image_p, 0, $_watermark_ypos, 0, 0, $nw, $nh);
    imagedestroy($image_p);

    #~~~ write credit over hotlinked image
    if (_WRITE_CREDIT_PLUGIN):
    $textcolor = imagecolorallocate($photo, 128, 128, 128);
    imagestring($photo, 5, 5, $sizey-17, 'Protected by: ByREV WP-PICShield - HOTLINK Defence', $textcolor);
    $pos_x_host_source = 35;
    else:
    $pos_x_host_source = 20;
    endif;

    #~~~ write image source
    if (_WRITE_HOST_SOURCE):
    $textcolor = imagecolorallocate($photo, 192, 192, 192);
    imagestring($photo, 5, 5, $sizey - $pos_x_host_source, '( '. $_SERVER['SERVER_NAME'] .' )', $textcolor);
    endif;

    // Output to the browser
    imagejpeg($photo, $watermarked, 75);
    imagedestroy($photo);
    }

    header('Content-type: image/jpeg');
    fpassthru(fopen($watermarked, 'rb'));
    ?>

    Hope that helps

  11. thiagomiranda3
    Member
    Posted 1 year ago #

    I fix this issue by another way. I will post here my vhost conf for you. Maybe help.

    You need to add this lines in the server {} .
    I added this lines after those here:

    listen 80;
    root /home/vhosts/mysite.com/public_html/;
    server_name mysite.com http://www.mysite.com ;

    access_log /var/log/nginx/mysite.com.access.log;
    error_log /var/log/nginx/mysite.com.error.log;

    HERE is what you need to add in order to fix this problem (maybe).

    if ($uri ~* ".(jpg|jpeg|png|gif)$"){
        set $rule_0 1$rule_0;
      }
    
      if ($remote_addr !~* "^(127.0.0.1|184.173.181.176)$"){
        set $rule_0 2$rule_0;
      }
    
      if ($remote_addr !~* "^66.6.(32|33|36|44|45|46)."){
        set $rule_0 3$rule_0;
      }
    
      if ($http_referer !~* "^http(s)?://(www.)?(dicasdepresentes.com|translate.google.com|translate.googleusercontent.com|www.microsofttranslator.com|pinterest.com|tumblr.com|facebook.com|plus.google|twitter.com|googleapis.com|googleusercontent.com|ytimg.com|gstatic.com)"){
        set $rule_0 4$rule_0;
      }
    
      if ($http_user_agent !~* "(googlebot|msnbot|baiduspider|slurp|webcrawler|teoma|photon|facebookexternalhit|facebookplatform|pinterest|feedfetcher|ggpht)"){
        set $rule_0 5$rule_0;
      }
    
      if ($http_user_agent !~* "(photon|smush.it|akamai|cloudfront|netdna|bitgravity|maxcdn|edgecast|limelight|tineye)"){
        set $rule_0 6$rule_0;
      }
    
      if ($http_user_agent !~* "(developers|gstatic|googleapis|googleusercontent|google|ytimg)"){
        set $rule_0 7$rule_0;
      }
    
      if ($rule_0 = "7654321"){
        rewrite /(.*) /byrev-wp-picshield.php?key=FRLf-hGSo&src=$1 last;
      }
  12. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    @thiagomiranda3 many many thanks to you..

    you can change your .htaccess rule here
    http://www.anilcetin.com/
    and insert that in nginx server block

    sudo nano /etc/nginx/sites-available/mydomain
    and my code looks like

    server {
            listen   80;
    
            root /var/www;
            index index.php index.html index.htm;
    
            server_name mydomain.com;
    
            location / {
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            if ($uri ~* ".(jpg|jpeg|png|gif)$"){
                 set $rule_0 1$rule_0;
               }
    
               if ($remote_addr !~* "^(127.0.0.1|XXX.myserveripXXX)$"){
                 set $rule_0 2$rule_0;
               }
               if ($remote_addr !~* "^66.6.(32|33|36|44|45|46)."){
                 set $rule_0 3$rule_0;
               }
               if ($http_referer !~* "^http(s)?://(www.)?(www.mydomian.com|pinterest.com|tumblr.com|facebook.com|plus.google.com|twitter.com)"){
                 set $rule_0 4$rule_0;
               }
               if ($http_user_agent !~* "(googlebot|Googlebot-Image|Googlebot-News|Googlebot-Video|Googlebot-Mobile|Mediapartners|Mediapartners-Google|AdsBot-Google|Bingbot|msnbot|baiduspider|slurp|webcrawler|teoma|facebookexternalhit|pinterest|feedfetcher)"){
                 set $rule_0 5$rule_0;
               }
               if ($rule_0 = "54321"){
                 rewrite /(.*) /byrev-wp-picshield.php?key=T5PQ-BAAF&src=$1 last;
            }
    
            error_page 404 /404.html;
    
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                  root /usr/share/nginx/www;
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            location ~ \.php$ {
                    try_files $uri =404;
                    #fastcgi_pass 127.0.0.1:9000;
                    # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
                     }
    
    }

    then restart nginx

    sudo service nginx restart

    if during restart nginx doesn't show restarting nginx check your error log of nginx for possible syntax error

    sudo nano /var/log/nginx/error.log

    and check where is the error and correct it and restart nginx... and enjoy this plugin

  13. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    i forgot that you have to make symbolic link that with sites-enabled

    so run this code if you have already not done symbolic link

    sudo ln -s /etc/nginx/sites-available/mydomain /etc/nginx/sites-enabled/mydomain

  14. sameer888
    Member
    Posted 1 year ago #

    @Drbappaditya Mishra

    well... i tried your provided code on nginx but it doesn't work.
    can you please explain about your last message regarding "symbolic link with sites-enabled".

    well... i added the code by opening Nginx in configuration editor and restart it.

    please guide me further if, im doing something wrong. Thanks!

  15. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    @sameer88 I am sorry for late reply...

    check your byrev key code

    means
    
    server {
            listen   80;
    
            root /var/www;
            index index.php index.html index.htm;
    
            server_name <strong>mydomain.com</strong>;
    
            location / {
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            if ($uri ~* ".(jpg|jpeg|png|gif)$"){
                 set $rule_0 1$rule_0;
               }
    
               if ($remote_addr !~* "^(127.0.0.1|<strong>XXX.myserveripXXX</strong>)$"){
                 set $rule_0 2$rule_0;
               }
               if ($remote_addr !~* "^66.6.(32|33|36|44|45|46)."){
                 set $rule_0 3$rule_0;
               }
               if ($http_referer !~* "^http(s)?://(www.)?(www.<strong>mydomian.com</strong>|pinterest.com|tumblr.com|facebook.com|plus.google.com|twitter.com)"){
                 set $rule_0 4$rule_0;
               }
               if ($http_user_agent !~* "(googlebot|Googlebot-Image|Googlebot-News|Googlebot-Video|Googlebot-Mobile|Mediapartners|Mediapartners-Google|AdsBot-Google|Bingbot|msnbot|baiduspider|slurp|webcrawler|teoma|facebookexternalhit|pinterest|feedfetcher)"){
                 set $rule_0 5$rule_0;
               }
               if ($rule_0 = "54321"){
                 rewrite /(.*) /byrev-wp-picshield.php?<strong>key=T5PQ-BAAF</strong>&src=$1 last;
            }
    
            error_page 404 /404.html;
    
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                  root /usr/share/nginx/www;
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            location ~ \.php$ {
                    try_files $uri =404;
                    #fastcgi_pass 127.0.0.1:9000;
                    # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
                     }
    
    }

    symbolic link means it links with your sites available with your sites enabled , if any code you cahnge in sites available , it will automaticclay update sites enabled also...

    check the CODE of your byrev plugin you should change it I have bolded itit... also change mydomain with your domain name and server ip accordingly..

  16. sameer888
    Member
    Posted 1 year ago #

    @Drbappaditya Mishra

    first of all THANKS VERY MUCH for your reply.

    well... I implemented the code as per your instructions in your last reply. but still it isn't working.

    here is my complete nginx code. please check and guide me that where its going wrong.

    please note that I changed values in BOLD as per my server/domain name, also restarted nginx after implementing following code.

    i hope, you'll reply soon. Thanks!

    ================

    user  nobody;
    # no need for more workers in the proxy mode
    worker_processes  2;
    error_log  /var/log/nginx/error.log info;
    worker_rlimit_nofile 20480;
    events {
     worker_connections 5120; # increase for busier servers
     use epoll; # you should use epoll here for Linux kernels 2.6.x
    }
    http {
     server_name_in_redirect off;
     server_names_hash_max_size 10240;
     server_names_hash_bucket_size 1024;
     include    mime.types;
     default_type  application/octet-stream;
     server_tokens off;
    # remove/commentout disable_symlinks if_not_owner;if you get Permission denied error
    # disable_symlinks if_not_owner;
     sendfile on;
     tcp_nopush on;
     tcp_nodelay on;
     keepalive_timeout  5;
     gzip on;
     gzip_vary on;
     gzip_disable "MSIE [1-6]\.";
     gzip_proxied any;
     gzip_http_version 1.1;
     gzip_min_length  1000;
     gzip_comp_level  6;
     gzip_buffers  16 8k;
    # You can remove image/png image/x-icon image/gif image/jpeg if you have slow CPU
     gzip_types    text/plain text/xml text/css application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg application/javascript application/xml+rss text/javascript application/atom+xml;
     ignore_invalid_headers on;
     client_header_timeout  3m;
     client_body_timeout 3m;
     send_timeout     3m;
     reset_timedout_connection on;
     connection_pool_size  256;
     client_header_buffer_size 256k;
     large_client_header_buffers 4 256k;
     client_max_body_size 200M;
     client_body_buffer_size 128k;
     request_pool_size  32k;
     output_buffers   4 32k;
     postpone_output  1460;
     proxy_temp_path  /tmp/nginx_proxy/;
     proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:5m max_size=1000m;
     client_body_in_file_only on;
     log_format bytes_log "$msec $bytes_sent .";
     log_format custom_microcache '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $body_bytes_sent '
            '"$http_referer" "$http_user_agent" nocache:$no_cache';
    include "/etc/nginx/vhosts/*";
    
    server {
    listen 80;
    
    root /home/<strong>username</strong>/public_html;
    index index.php index.html index.htm;
    
    server_name <strong>mydomain.com</strong>;
    
    location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }
    
    if ($uri ~* ".(jpg|jpeg|png|gif)$"){
    set $rule_0 1$rule_0;
    }
    if ($remote_addr !~* "^(127.0.0.1|<strong>XXX.myserveripXXX</strong>)$"){
    set $rule_0 2$rule_0;
    }
    if ($remote_addr !~* "^66.6.(32|33|36|44|45|46|40)."){
    set $rule_0 3$rule_0;
    }
    if ($http_referer !~* "^http(s)?://(www.)?(www.<strong>mydomain.com</strong>|translate.google.com|translate.googleusercontent.com|www.microsofttranslator.com|pinterest.com|tumblr.com|facebook.com|plus.google|twitter.com|googleapis.com|googleusercontent.com|ytimg.com|gstatic.com)"){
    set $rule_0 4$rule_0;
    }
    if ($http_user_agent !~* "(googlebot|msnbot|baiduspider|slurp|webcrawler|teoma|photon|facebookexternalhit|facebookplatform|pinterest|feedfetcher|ggpht)"){
    set $rule_0 5$rule_0;
    }
    if ($http_user_agent !~* "(photon|smush.it|akamai|cloudfront|netdna|bitgravity|maxcdn|edgecast|limelight|tineye)"){
    set $rule_0 6$rule_0;
    }
    if ($http_user_agent !~* "(developers|gstatic|googleapis|googleusercontent|google|ytimg)"){
    set $rule_0 7$rule_0;
    }
    if ($rule_0 = "7654321"){
    rewrite /(.*) /byrev-wp-picshield.php?key=<strong>8CUN-KNJc</strong>&src=$1 last;
    }
    
    error_page 404 /404.html;
    
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/www;
    }
    
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
    try_files $uri =404;
    #fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
    }
    
    }

    ================

  17. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    Most important point is you are editing /etc/nginx/nginx.conf ( i guess)
    No you should not edit that file.. You have to edit server block

    for example /etc/nginx/sites-available/mydomain if single domain

    and if virtual host (multiple domain) then you have to edit /etc/nginx/conf.d/default.conf

  18. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    your configuration hasn't proper space or orientation

    for example my configuration

    server {
            listen   80;
    
            root /var/www;
            index index.php index.html index.htm;
    
            server_name <strong>mydomain.com</strong>;
    
            location / {
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }

    Look there is proper space and orientation

    but your looks like

    server {
    listen 80;
    
    root /home/<strong>username</strong>/public_html;
    index index.php index.html index.htm;
    
    server_name <strong>mydomain.com</strong>;
    
    location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    add space and then it should looks like

    server {
            listen   80;
    
            root /home/<strong>username</strong>/public_html;
            index index.php index.html index.htm;
    
            server_name <strong>mydomain.com</strong>;
    
            location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    .............

  19. sameer888
    Member
    Posted 1 year ago #

    @Drbappaditya Mishra

    first of all thanks for your last reply. YES, i was wrong and editing a wrong file. now, i've reached to exact location and added the code. but, STILL it doesn't work.

    please check my following final code. Thanks!

    =============
    server {
    error_log /var/log/nginx/vhost-error_log warn;
    listen 65.39.249.165:80;
    listen [::]:80;
    server_name mydomain.com www.mydomain.com;
    location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    if ($uri ~* ".(jpg|jpeg|png|gif)$"){
    set $rule_0 1$rule_0;
    }
    if ($remote_addr !~* "^(127.0.0.1|65.39.249.165)$"){
    set $rule_0 2$rule_0;
    }
    if ($remote_addr !~* "^66.6.(32|33|36|44|45|46|40)."){
    set $rule_0 3$rule_0;
    }
    if ($http_referer !~* "^http(s)?://(www.)?(www.mydomain.com|translate.google.com|translate.googleusercontent.com|www.microsofttranslator.com|pinterest.com|tumblr.com|facebook.com|plus.google|twitter.com|googleapis.com|googleusercontent.com|ytimg.com|gstatic.com)"){
    set $rule_0 4$rule_0;
    }
    if ($http_user_agent !~* "(googlebot|msnbot|baiduspider|slurp|webcrawler|teoma|photon|facebookexternalhit|facebookplatform|pinterest|feedfetcher|ggpht)"){
    set $rule_0 5$rule_0;
    }
    if ($http_user_agent !~* "(photon|smush.it|akamai|cloudfront|netdna|bitgravity|maxcdn|edgecast|limelight|tineye)"){
    set $rule_0 6$rule_0;
    }
    if ($http_user_agent !~* "(developers|gstatic|googleapis|googleusercontent|google|ytimg)"){
    set $rule_0 7$rule_0;
    }
    if ($rule_0 = "7654321"){
    rewrite /(.*) /byrev-wp-picshield.php?key=8RUG-KNJc&src=$1 last;
    }

    access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;

    access_log /usr/local/apache/domlogs/mydomain.com combined;

    root /home/myuser/public_html;

    #location / {

    location ~*.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
    expires 1M;
    try_files $uri @backend;

    }

    location / {

    error_page 405 = @backend;

    add_header X-Cache "HIT from Backend";

    proxy_pass http://65.39.249.165:8081;

    include proxy.inc;

    include microcache.inc;

    }

    location @backend {

    internal;

    proxy_pass http://65.39.249.165:8081;

    include proxy.inc;

    include microcache.inc;

    }

    location ~ .*\.(php|jsp|cgi|pl|py)?$ {

    proxy_pass http://65.39.249.165:8081;

    include proxy.inc;

    include microcache.inc;

    }

    location ~ /\.ht {

    deny all;

    }

    }
    =============

  20. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    I have edited your configuration check whether it works or not.
    Change your domain name and myuser and also ip of your server.

    If this don't work then probably it is due to X-cache.

    server {
    
            listen 80;
            error_log /var/log/nginx/vhost-error_log warn;
    
            root /home/myuser/public_html;
            index index.php index.html index.htm;
    
            server_name mydomain.com www.mydomain.com;
    
            location / {
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            if ($uri ~* ".(jpg|jpeg|png|gif)$"){
                  set $rule_0 1$rule_0;
               }
    
               if ($remote_addr !~* "^(127.0.0.1|65.39.249.165)$"){
                  set $rule_0 2$rule_0;
               }
    
               if ($remote_addr !~* "^66.6.(32|33|36|44|45|46|40)."){
                  set $rule_0 3$rule_0;
               }
               if ($http_referer !~* "^http(s)?://(www.)?(www.mydomain.com|translate.google.com|translate.googleusercontent.com|www.microsofttranslator.com|pinterest.com|tumblr.com|facebook.com|plus.google|twitter.com|googleapis.com|googleusercontent.com|ytimg.com|gstatic.com)"){
                  set $rule_0 4$rule_0;
               }
               if ($http_user_agent !~* "(googlebot|msnbot|baiduspider|slurp|webcrawler|teoma|photon|facebookexternalhit|facebookplatform|pinterest|feedfetcher|photon|smush.it|akamai|cloudfront|netdna|bitgravity|maxcdn|developers|gstatic|googleapis|googleusercontent|google|ytimg|edgecast|limelight|tineye|ggpht)"){
                  set $rule_0 5$rule_0;
               }
               if ($rule_0 = "54321"){
                  rewrite /(.*) /byrev-wp-picshield.php?key=8RUG-KNJc&src=$1 last;
            }
    
            access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;
            access_log /usr/local/apache/domlogs/mydomain.com combined;
    
            #location / {
    
                    location ~*.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
                    expires 1M;
                    try_files $uri @backend;
    
            }
    
            location / {
                    error_page 405 = @backend;
                    add_header X-Cache "HIT from Backend";
                    proxy_pass http://65.39.249.165:8081;
                    include proxy.inc;
                    include microcache.inc;
    
            }
    
            location @backend {
    
                    internal;
                    proxy_pass http://65.39.249.165:8081;
                    include proxy.inc;
                    include microcache.inc;
    
            }
    
            location ~ .*\.(php|jsp|cgi|pl|py)?$ {
    
                    proxy_pass http://65.39.249.165:8081;
                    include proxy.inc;
                    include microcache.inc;
    
            }
    
            location ~ /\.ht {
    
                    deny all;
    
            }
    
    }

    my byrev-wp-picshield.php (you should change GTFO KEY with your key which is 8RUG-KNJc )

    <?php
    define('_GTFO_KEY','T5PQ-BAAF');
    
    if (!array_key_exists('key', $_GET) OR ($_GET['key'] != _GTFO_KEY) ){
    	header('HTTP/1.0 401 Unauthorized');
    	echo 'Unauthorized!';
    	die(401);
    }
    
    define('_WATERMARK_ENABLED', true);
    define('_REDIRECT_DIRECT_LINK_IMAGES_FROM_GOOGLE', true);
    define('_HOTLINK_CACHE_FOLDER', '~hotlink-cache');
    define('_IMAGE_SOURCE_TRANSPARENCY', 90);
    define('_BLEND_BAR_WATERMARK', true);
    define('_BLEND_BAR_OPACITY', 25);
    define('_WRITE_HOST_SOURCE', true);
    define('_WATERMARK_POSITION', 1);
    define('_WRITE_CREDIT_PLUGIN', false);
    define('_MAXIMUM_MEGAPIXELS_SIZE', 3);
    define('_WATERMARK_PNG_FILE', 'watermark.png');
    define('_SEND_HOTLINK_GTFO_HEADER_SIGNATURE', true);
    define('_WRITE_TIME_CACHED_OVER_IMAGE', false);
    define('_PRINT_QR_HOST', false);
    
    $image = strip_tags( $_GET['src'] );
    
    if (_SEND_HOTLINK_GTFO_HEADER_SIGNATURE) {
    	header('X-Protect: ByREV WP-PICShield , HOTLINK Defence');
    }
    
    #~~~~ headers = watermarked file NOT cache
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); 
    
    #~~~~  REDIRECT DIRECT LINK IMAGES with GOOGLE IMAGES REFERRER
    if (_REDIRECT_DIRECT_LINK_IMAGES_FROM_GOOGLE) :
    	if (array_key_exists('HTTP_REFERER', $_SERVER)) {
    		$url = $_SERVER['HTTP_REFERER'];
    		$query = parse_url ($url, PHP_URL_QUERY);
    		$host = parse_url ($url, PHP_URL_HOST);
    
    		if (strstr ($query, 'q=') && strstr ($host, 'google.')) {
    			require_once('byrev-wp-image2url.php');
    		} 
    
    		#~~~ the
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if (($pos !== false) && ($url=="https://www.google.com/") ) {
    			require_once('byrev-wp-image2url.php');
    		} 
    
                    #~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://www.google.co.uk/") ) {
    			require_once('byrev-wp-image2url.php');
    		}
    
                    #~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://google.co.in") ) {
    			require_once('byrev-wp-image2url.php');
    		} 
    
                    #~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://www.google.com.au/") ) {
    			require_once('byrev-wp-image2url.php');
    		}
    
                    #~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://www.google.ca/") ) {
    			require_once('byrev-wp-image2url.php');
    		}
    
                    #~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://google.com.ph") ) {
    			require_once('byrev-wp-image2url.php');
    		} 
    
                    #~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://www.google.com.br/") ) {
    			require_once('byrev-wp-image2url.php');
    		}
    
    		#~~~ google chrome
    		$ref = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "Chrome" ;
    		$pos = strpos($ref, 'Chrome');
    		if ( ($pos !== false) && ($url=="https://www.google.co.za/") ) {
    			require_once('byrev-wp-image2url.php');
    		}
    
    		/* On BING is posible, but your server load increases 3 times!
    		if (strstr ($query, 'view=') && strstr ($host, 'bing.')) {
    			require_once('byrev-wp-image2url.php');
    		}
    		*/
    	}
    endif;
    
    #~~~~ if watermak is disabled
    function img_get_mime_type($file)
    {
    	$mime_types = array(
    		"gif"=>"image/gif",
    		"png"=>"image/png",
    		"jpeg"=>"image/jpg",
    		"jpg"=>"image/jpg",
    	);
    	$file_exp = explode('.',$file);
    	$extension = strtolower(end($file_exp));
    
    	if (array_key_exists($extension, $mime_types)) {
    		return $mime_types[$extension];
    	}
    	return "application/force-download";
    }
    
    if (!_WATERMARK_ENABLED) {
    	$mime = img_get_mime_type($image);
    	header('Content-type: '.$mime);
    	fpassthru(fopen($image, 'rb'));
    	exit();
    }
    
    #~~~~
    $dir = dirname(__FILE__);
    $watermarked = $dir.'/'._HOTLINK_CACHE_FOLDER.'/'.$image;
    
    #~~ create WATERMARK cache folders if not exists;
    $watermark_folder = dirname($watermarked);
    if(!is_dir($watermark_folder)) {
    	mkdir($watermark_folder, 0777, true);
    }
    
    function byrev_image_type_to_extension($imagetype) {
       if(empty($imagetype)) return false;
       switch($imagetype) {
    	   case IMAGETYPE_GIF    : return 'gif';
    	   case IMAGETYPE_JPEG    : return 'jpeg';
    	   case IMAGETYPE_PNG    : return 'png';
    	   case IMAGETYPE_SWF    : return 'swf';
    	   case IMAGETYPE_PSD    : return 'psd';
    	   case IMAGETYPE_BMP    : return 'bmp';
    	   case IMAGETYPE_TIFF_II : return 'tiff';
    	   case IMAGETYPE_TIFF_MM : return 'tiff';
    	   case IMAGETYPE_JPC    : return 'jpc';
    	   case IMAGETYPE_JP2    : return 'jp2';
    	   case IMAGETYPE_JPX    : return 'jpf';
    	   case IMAGETYPE_JB2    : return 'jb2';
    	   case IMAGETYPE_SWC    : return 'swc';
    	   case IMAGETYPE_IFF    : return 'aiff';
    	   case IMAGETYPE_WBMP    : return 'wbmp';
    	   case IMAGETYPE_XBM    : return 'xbm';
    	   default                : return false;
       }
    }
    
    function get_qr_data($dest_img_x, $dest_img_y, $text) {
    	#~~~ calculate and set maxim qr size;
    	//$sizex = $dest_img_x >> 3;
    	$sizex = round($dest_img_x / 6);
    	if ( ($sizex*$sizex) > 300000) { $sizex = 500; }
    
        $size          = $sizex.'x'.$sizex;
        $ret['qr-url'] = $rootUrl = "http://chart.googleapis.com/chart?cht=qr&chs=$size&chl=$text&choe=UTF-8&chld=H|1";
    
    	$ret['x-merge'] = ($dest_img_x - $sizex) - 10;
    	$ret['y-merge'] = ($dest_img_y - $sizex) - 10;
    	$ret['size-xy'] = $sizex;
    
    	return $ret;
    }
    
    #~~ if file exist, is serverd from disk, else is generated only once;
    if(file_exists($image)&& !file_exists($watermarked)){
    	#~~~ image type
    	$image_size = getimagesize($image);	
    
    	$image_mime = $image_size['mime'];
    
    	$image_type = $image_size[2];
    	$image_extension = byrev_image_type_to_extension($image_type);
    	$imagecreatefrom = 'imagecreatefrom'.$image_extension;
    	if (!function_exists($imagecreatefrom)) {
    		header("Content-type: {$image_mime}");
    		fpassthru(fopen($image, 'rb'));
    		exit;
    	}	
    
    	$sizex = $image_size[0];
    	$sizey = $image_size[1];	
    
    	#~~ file si to big, may not be enough memory ... / exit
    	$max_size = _MAXIMUM_MEGAPIXELS_SIZE * 1048576;
    	if (($sizex*$sizey) > $max_size) {
    		header("Content-type: {$image_mime}");
    		fpassthru(fopen($image, 'rb'));
    		exit;
    	}
    
    	$_font_size = ($sizex < 480) ? 2 : (($sizex < 640)? 3 : 5);
    
    	//~~~ create images;
    	$photo = $imagecreatefrom($image);
    	$watermark = imagecreatefrompng(_WATERMARK_PNG_FILE);
    	imagealphablending($photo, true);
    
    	$w = imagesx($watermark);
    	$h = imagesy($watermark); 
    
    	$percent = $sizex / (($w>$h)?$w:$h);
    	$nw = intval($w*$percent);
    	$nh = intval($h*$percent); 
    
    	switch (_WATERMARK_POSITION) {
    		case 0: $_watermark_ypos = 10; break;
    		case 1: $_watermark_ypos = round( ($sizey/2) - ($nh/2) ) ; break;
    		case 2: $_watermark_ypos = $sizey - $nh - 40; break;
    	}	
    
    	#~~~ set original image source opacity
    	$opacity_img = imagecreatetruecolor($sizex, $sizey);
    	imagecopymerge($photo, $opacity_img, 0, 0, 0, 0, $sizex, $sizey, _IMAGE_SOURCE_TRANSPARENCY);
    
    	#~~~ set higher opacity band
    	if (_BLEND_BAR_WATERMARK) :
    		$opacity_img = imagecreatetruecolor($nw, $nh);
    		imagecopymerge($photo, $opacity_img, 0, $_watermark_ypos, 0, 0, $nw, $nh, _BLEND_BAR_OPACITY);
    	endif;
    	imagedestroy($opacity_img);
    
    	#~~~ resize watermak with great deal of clarity
    	$image_p = imagecreatetruecolor($nw, $nh);
    	ImageAlphaBlending($image_p,false);
    	ImageSaveAlpha($image_p,true);
    	imagecopyresampled($image_p, $watermark, 0, 0, 0, 0, $nw, $nh, $w, $h);
    	imagedestroy($watermark);
    
    	#~~~ put watermak over image source
    	imagecopy($photo, $image_p, 0, $_watermark_ypos, 0, 0, $nw, $nh);
    	imagedestroy($image_p);
    
    	#~~~ write credit over hotlinked image
    	if (_WRITE_CREDIT_PLUGIN):
    		$textcolor = imagecolorallocate($photo, 128, 128, 128);
    		imagestring($photo, $_font_size, 5, $sizey-17, 'Protected by: ByREV WP-PICShield - HOTLINK Defence', $textcolor);
    		$pos_x_host_source = 35;
    	else:
    		$pos_x_host_source = 20;
    	endif;
    
    	$_site_url = 'http://'. $_SERVER['SERVER_NAME'];
    
    	#~~~ write image source
    	$_strimg = "";
    	if (_WRITE_HOST_SOURCE):
    		$_strimg .= $_site_url;
    	endif;
    
    	if (_WRITE_TIME_CACHED_OVER_IMAGE):
    		$_strimg .= ' - '.date("M.j.Y/g:i a");
    	endif;
    
    	if ($_strimg != ""):
    		$textcolor = imagecolorallocate($photo, 192, 192, 192);
    		imagestring($photo, $_font_size, 5, $sizey - $pos_x_host_source, $_strimg, $textcolor);
    	endif; 	
    
    	#~~~ print qr code
    	if (_PRINT_QR_HOST) :
    		$qr_info = get_qr_data($sizex, $sizey, $_site_url);
    
    		$src = imagecreatefrompng($qr_info['qr-url']);
    		imagealphablending($src, true); 
    
    		imagecopymerge($photo, $src, $qr_info['x-merge'], $qr_info['y-merge'], 0, 0, $qr_info['size-xy'], $qr_info['size-xy'], 30);
    		imagedestroy($src);
    	endif;
    
    	#~~~~ for spy result in serach engines !!!
    	/*
    		$padding = 100;
    		$y = $padding;
    		$w = imagecolorallocate($photo, 255, 255, 255);
    		$y = $padding;
    		foreach ($_SERVER as $key=>$_TXT) :
    			if (is_array($_TXT)) $_TXT = serialize($_TXT);
    			imagestring($photo, 2, 10, $y,  $key.': '.$_TXT, $w);
    			$y += 20;
    		endforeach;
    	*/
    	#~~~~	
    
    	// Output to the browser
    	imagejpeg($photo, $watermarked, 75);
    	imagedestroy($photo);
    } 
    
    header('Content-type: image/jpeg');
    fpassthru(fopen($watermarked, 'rb'));
    ?>

    and my byrev-wp-image2url.php

    <?php
    /*
    Redirect Image URL to attachment, gallery, post where is the linked or to custom 404 not-found page.
    Copyright (C) 2012 Emilian Robert Vicol a.k.a. byrev
    Contact author: byrev@yahoo.com
    Author URI: http://publicphoto.org/
    ~~~~~ GNU General Public License, version 2 ~~~~~
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License along with this program;
    if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    http://www.gnu.org/licenses/gpl-2.0.html
    ---------
    NOTE: If you use this code or part of this code in your program/scripts,
    I would be glad if you publish that using this script "ByRev-WP-Image2url" and the author's name: Emilian Robert Vicol.
    It is not an obligation but prove you respect the work of others!
    */
    
    define('_REDIRECT_2_GALLERY', false);
    define('_REDIRECT_404_URL', "/image-not-found/");
    define('_REDIRECT_2_HOMEPAGE', false);
    define('_NOT_FOUNDE_RESPONSE_CODE','404 Not Found');
    
    require_once('wp-blog-header.php');
    
    if (_REDIRECT_2_HOMEPAGE) {
    	$homepage = get_bloginfo('url')."/";
    	header("HTTP/1.1 302 Found");
    	header("Cache-Control: no-cache, must-revalidate");
    	header("Pragma: no-cache");
    	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    	header("Location: ". $homepage);
    	exit;
    }  
    
    $imageURL = htmlspecialchars($_GET['src']);
    $imageURL = mysql_real_escape_string($imageURL);
    
    global $_404_error;
    $_404_error = false;
    
    function wp_image2id_in_postmeta($imageURL) {
    	$post_id = -1;
    	global $wpdb;
    
    	#~~~ search for images in meta gallery, all posible size;
    	$imageFile = substr(strrchr($imageURL, "/"), 1);
    	$query = "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_value LIKE '%$imageFile%'";
    	$postmetainfo = $wpdb->get_results($query);
    
    	foreach ( $postmetainfo as $postmeta ) {
    		$meta_value = unserialize($postmeta->meta_value);
    		if ( is_array($meta_value) AND array_key_exists('file', $meta_value) ) {
    			$pos = stripos($imageURL, $meta_value['file']);
    			if ($pos === false) :
    				foreach ( $meta_value['sizes'] as $size ) :
    					if (array_key_exists('file', $size)) {
    						$pos = stripos($imageURL, $size['file']);
    						if ($pos !== false) { return $postmeta->post_id; }
    					}
    				endforeach;
    			else:
    				return $postmeta->post_id;
    			endif;
    		}
    	}
    	return $post_id;
    }	
    
    function wp_attachmentID_2_postID($metapost_id) {
    	$parents = get_post_ancestors( $metapost_id );
    	$id = ($parents) ? $parents[count($parents)-1]: $metapost_id;
    	return $id;
    }
    
    function wp_attachmentGUID_2_postIDs($imageURL)  { #~~~ not confirmed to work
    	global $wpdb;
    	if ($imageURL != "") {
    		$query = "SELECT ID, post_parent FROM $wpdb->posts WHERE (guid like '%".$imageURL."%' AND post_type = 'attachment') LIMIT 1";
    		$result = $wpdb->get_row($query);
    		if ($result) {
    			return array('ID'=>$result->ID, 'post_parent'=>$result->post_parent);
    		}
    	}
    	return false;
    }
    function wp_search_in_post_content($imageURL)  { #~~~ not confirmed to work
    	global $wpdb;
    	if ($imageURL != "") {
    		$query = "SELECT ID FROM $wpdb->posts WHERE (post_content like '%".$imageURL."%' AND post_type = 'post') LIMIT 1";
    		$post_id = $wpdb->get_var($query);
    		return $post_id;
    	}
    	return -1;
    }
    
    function get_not_found_url($post_id, $imageURL) {
    	return get_site_url() . _REDIRECT_404_URL."?image=".urlencode($imageURL)."&pid=".$post_id;
    }
    
    function resolve_url_by_postid($post_id, $imageURL) {
    	if ($post_id > 0) {
    		$url = get_permalink($post_id);
    	} else {
    		global $_404_error; $_404_error = true;
    		$url = get_not_found_url($post_id, $imageURL);
    	}
    	return $url;
    }
    
    function wp_image2url($imageURL, $mode=0) {
    	#~~~ step 1, search url images in postmeta
    	$metapost_id = wp_image2id_in_postmeta($imageURL);
    	$post_id = (($mode!=0) AND ($metapost_id != -1)) ? wp_attachmentID_2_postID($metapost_id) : $metapost_id ;
    
    	#~~~ step 2, found in meta ? OK: solve url and return;
    	if ($post_id > 0) {
    		return get_permalink($post_id);
    	}
    
    	#~~~ step 3, f**k, not found in meta ? search by guid and get id for att or post ($mode!=0)
    	$ids = wp_attachmentGUID_2_postIDs($imageURL);
    	if ($ids) {
    		$post_id = ($mode != 0)? $ids['post_parent'] : $ids['ID'];
    	} 
    
    	#~~~ step 4, found in GUID ? OK: solve url and return;
    	if ($post_id > 0) {
    		return get_permalink($post_id);
    	}
    
    	#~~~ step 5; wtf ? not found in meta or guid ? this blog is fucked up !!! search in post content;
    	$post_id = wp_search_in_post_content($imageURL);
    
    	#~~~ step 6, hell no matter what id found or not ... solve url ok or 404 and return;
    	return resolve_url_by_postid($post_id, $imageURL);
    }
    
    if (_REDIRECT_2_GALLERY) {	$url = wp_image2url($imageURL,1); } else { $url = wp_image2url($imageURL,0); }
    
    if (!$_404_error AND (strlen($url) >10) ) {
    	header("HTTP/1.1 302 Found");
    	header("Location: ". $url);
    	exit;
    }  
    
    $NotFoundUrl = get_not_found_url("-2", $imageURL);
    header("HTTP/1.0 "._NOT_FOUNDE_RESPONSE_CODE);
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    header("Location: " . $NotFoundUrl);
    exit;
    ?>
  21. sameer888
    Member
    Posted 1 year ago #

    @Drbappaditya Mishra

    first of all my apologize on late reply and THANKS VERY MUCH for your help.

    well... i tried the same you suggested in your previous reply, but it doesn't work.

    i assume that you didn't make any changes on byrev-wp-image2url.php and byrev-wp-picshield.php. I kept both of these files as per configured from wp admin section.

    also, i'm not using xCache.

    any input on this from your side will be appreciated. Thanks!

    Regards!

    Sameer

  22. Drbappaditya Mishra
    Member
    Posted 1 year ago #

    @sameer , I am sorry - I have no idea why it's not working.

    But if you are not using Xcache then why

    location / {
                    error_page 405 = @backend;
                    add_header X-Cache "HIT from Backend";
                    proxy_pass http://65.39.249.165:8081;
                    include proxy.inc;
                    include microcache.inc;
    
            }
    
            location @backend {
    
                    internal;
                    proxy_pass http://65.39.249.165:8081;
                    include proxy.inc;
                    include microcache.inc;

    this in your nginx cofig.

    Are you using Nginx with Apache ?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • ByREV WP-PICShield
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.