Home Forums WordPress Plugins Hide My WP not sure why nginx rewrite is not performed

This topic is: not resolved

This topic contains 9 replies, has 2 voices, and was last updated by  Suman Maharjan 1 week, 6 days ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #18174
    FunGuy
    Post count: 8

    I want to perform a few rewrites:

    this actually works:

    rewrite ^/includes/(.*) /wordpress/wp-includes/$1?putyo_happybits=administrator last;

    and I get this: http://everhide.wordpress.dev/includes/css/dashicons.min.css?ver=4.8.2 (wp-includes are changed to includes)

    I also want to do the same for uploads:

    rewrite ^/files/(.*) http:/everhide.wordpress.dev/content/uploads/$1?putyo_happybits=administrator last;

    Can not wrap my head around why this does not work.

    #18184
    Suman Maharjan
    Post count: 7142
    This reply has been marked as private.
    #18197
    FunGuy
    Post count: 8

    This is what plugin actually suggests:

    rewrite ^/files/(.*) /wordpress/http:/everhide.wordpress.dev/content/uploads/$1?putyo_happybits=administrator last;
    rewrite ^/modules/(.*) /wordpress/http:/everhide.wordpress.dev/content/plugins/$1?putyo_happybits=administrator last;

    But this is straight away looks like something wrong.

    http:/everhide.wordpress.dev/ – is locally on a vagrant machine so not available externally. I still struggle a bit with this as I tried a lot of different variants and still can not make this to work, except for this:

    rewrite ^/includes/(.*) /wordpress/wp-includes/$1?putyo_happybits=administrator last;

    which works just fine.

    #18211
    Suman Maharjan
    Post count: 7142

    So, isn’t the following rule working?
    rewrite ^/files/(.*) /wordpress/wp-content/uploads/$1?putyo_happybits=administrator last;

    It’ll be difficult for us to check as the site is not available live. Can you please post here the HMWP rules generated when clicking on Nginx Configuration button?

    #18261
    FunGuy
    Post count: 8

    Hi, Suman,

    I deployed to a custom link so that you could see my problems:

    everhide.happybits.lt

    This is how nginx looks like:

    server {
    listen 80;
    server_name everhide.happybits.lt;
    root /srv/www/clients/everhide/current/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {

    # BEGIN Hide My WP

    rewrite ^/lib/js/embed\.min\.js /wp-includes/js/wp-embed.min.js?putyo_hide_my_wp=1234 last;
    rewrite ^/login /wordpress/wp-login.php?putyo_hide_my_wp=1234 last;
    rewrite ^/lib/(.*) /wordpress/wp-includes/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/files/(.*) /content/uploads/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/modules/(.*) /content/plugins/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/template/(.*) /content/themes/storefront/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/ajax /wordpress/wp-admin/admin-ajax.php?putyo_hide_my_wp=1234 last;

    # END Hide My WP

    try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }

    access_log off;
    error_log /var/log/nginx/everhide-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_read_timeout 180;
    }
    location ~ /\.ht {
    deny all;
    }

    }

    This is how wp-config.php is like originally:

    <?php
    /**
    * Set root path.
    */
    $rootPath = realpath(__DIR__ . ‘/..’);

    /**
    * Include the Composer autoloader.
    */
    include $rootPath . ‘/vendor/autoload.php’;

    /**
    * Set site URL.
    */
    $server_url = getenv(‘SITE_URL’);

    /**
    * Define environment.
    */
    define(‘APP_ENV’, getenv(‘APP_ENV’));

    /**
    * Set database details.
    */
    define(‘DB_NAME’, getenv(‘DB_NAME’));
    define(‘DB_USER’, getenv(‘DB_USER’));
    define(‘DB_PASSWORD’, getenv(‘DB_PASSWORD’));
    define(‘DB_HOST’, getenv(‘DB_HOST’));

    /**
    * Set debug mode.
    */
    define(‘WP_DEBUG’, getenv(‘WP_DEBUG’) === ‘true’ ? true : false);

    /**
    * SSL.
    */
    define(‘FORCE_SSL_ADMIN’, getenv(‘WP_FORCE_SSL’) === ‘true’ ? true : false);
    define(‘FORCE_SSL_LOGIN’, getenv(‘WP_FORCE_SSL’) === ‘true’ ? true : false);

    if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] === ‘https’)
    {
    $_SERVER[‘HTTPS’] = ‘on’;
    }

    /**
    * Set custom paths.
    * These are required because WordPress is installed in a subdirectory.
    */
    define(‘WP_CONTENT_URL’, $server_url . ‘/content’);
    define(‘WP_SITEURL’, $server_url . ‘/wordpress’);
    define(‘WP_HOME’, $server_url . ‘/’);
    define(‘WP_CONTENT_DIR’, __DIR__ . ‘/content’);

    define( ‘CONCATENATE_SCRIPTS’, false );
    // define( ‘SCRIPT_DEBUG’, true );

    /**
    * Usual WordPress stuff – don’t overide the ones you have already.
    */
    define(‘DB_CHARSET’, ‘utf8’);
    define(‘DB_COLLATE’, ”);

    // define(“ADMIN_COOKIE_PATH”, “/wordpress/panel”);

    /**
    * Authentication unique keys and salts.
    *
    * @link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service
    */
    define(‘AUTH_KEY’, ‘put your unique phrase here’);
    define(‘SECURE_AUTH_KEY’, ‘put your unique phrase here’);
    define(‘LOGGED_IN_KEY’, ‘put your unique phrase here’);
    define(‘NONCE_KEY’, ‘put your unique phrase here’);
    define(‘AUTH_SALT’, ‘put your unique phrase here’);
    define(‘SECURE_AUTH_SALT’, ‘put your unique phrase here’);
    define(‘LOGGED_IN_SALT’, ‘put your unique phrase here’);
    define(‘NONCE_SALT’, ‘put your unique phrase here’);

    /**
    * WordPress database table prefix.
    * Use something other than wp_ for security.
    */
    $table_prefix = getenv(‘DB_PREFIX’);

    /**
    * Absolute path to the WordPress directory.
    */
    if (!defined(‘ABSPATH’))
    {
    define(‘ABSPATH’, dirname(__FILE__) . ‘/’);
    }

    require_once(ABSPATH . ‘wp-settings.php’);

    /**
    * Start Suzie
    */
    suzie();

    Maybe the problem is that wordpress is in a sub directory?

    As you might see the embed file is failing and apart from includes nothing else is changed by the plugin and nginx (plugins to modules, uploads folder to files and etc.)

    I have amended a bit nginx configuration suggested by the plugin, original suggestion from the plugin is here:

    # BEGIN Hide My WP

    rewrite ^/lib/js/embed\.min\.js /wp-includes/js/wp-embed.min.js?putyo_hide_my_wp=1234 last;
    rewrite ^/login /wordpress/wordpress/wp-login.php?putyo_hide_my_wp=1234 last;
    rewrite ^/lib/(.*) /wordpress/wp-includes/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/files/(.*) /wordpress/http:/everhide.happybits.lt/content/uploads/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/modules/(.*) /wordpress/http:/everhide.happybits.lt/content/plugins/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/template/(.*) /wordpress/http:/everhide.happybits.lt/content/themes/storefront/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/ajax /wordpress/wp-admin/admin-ajax.php?putyo_hide_my_wp=1234 last;

    # END Hide My WP

    Please let me know what I could do to make this work.

    Thanks.

    • This reply was modified 2 weeks, 1 day ago by  FunGuy.
    #18276
    Suman Maharjan
    Post count: 7142

    Hi, I could see that you have added HMWP rules within “location { }” block. Please delete HMWP rules from there and add it within “server { }” block (you can add the rules just before the last “}”)
    Let us know!

    #18282
    FunGuy
    Post count: 8

    Hi,

    I changed to this:

    server {
    listen 80;
    server_name everhide.happybits.lt;
    root /srv/www/clients/everhide/current/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }

    access_log off;
    error_log /var/log/nginx/everhide-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_read_timeout 180;
    }

    location ~ /\.ht {
    deny all;
    }

    # BEGIN Hide My WP

    rewrite ^/lib/js/embed\.min\.js /wp-includes/js/wp-embed.min.js?putyo_hide_my_wp=1234 last;
    rewrite ^/login /wordpress/wp-login.php?putyo_hide_my_wp=1234 last;
    rewrite ^/lib/(.*) /wordpress/wp-includes/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/files/(.*) /content/uploads/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/modules/(.*) /content/plugins/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/template/(.*) /content/themes/storefront/$1?putyo_hide_my_wp=1234 last;
    rewrite ^/ajax /wordpress/wp-admin/admin-ajax.php?putyo_hide_my_wp=1234 last;

    # END Hide My WP
    }

    restarted nginx, but it did not take any effect – you can check in here: everhide.happybits.lt

    Maybe any more ideas?

    #18286
    Suman Maharjan
    Post count: 7142

    Nginx config looks fine. Can you please let us know your site’s backend login details as private reply so that we can look into it. Thanks!

    #18293
    FunGuy
    Post count: 8
    This reply has been marked as private.
    #18303
    Suman Maharjan
    Post count: 7142
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.