NGINX from all subdomains redirect 301 to the primary domain

Today I faced this problem, when configuring virtual hosts Nginx, after the customizations made and creating the appropriate configs, my subdomains began to refer through 301 Redirect to the main domain of the second level.

First I decided to recheck the correctness of the configuration and whether CloudFlare or SSL certificate could provoke this problem. But it turned out that the problem was not so much in the server, but in Google Chrome. It is therefore necessary to verify. Create a tab in Incognito mode and load the subdomain, if the subdomain is loaded, and if you are not in Incognito mode and pops up 301 redirect on the main domain, then the redirects were cached.

The only working method that was found is to remove the site caches in the following sequence:

  1. Go to Google Chrome developer mode
  2. Push F12
  3. At the top of the panel, you will find the vertical three dots, symbolizing the context menu.
  4. In the context menu select – Settings
  5. Network or Network tab, depending on localization
  6. Activate the tick – do not cache the page in developer mode.

After the steps are taken, try to open your subdomain with the developer panel.

These actions will remove all cached redirects, and a redirect of 301 to the main domain won’t work.

Selenium Webdriver + Java + XPath search item by URL part in href

When writing a bot for Instagram, using a stack of technologies selenium Webdriver, Java, XPath, encountered a problem.
Instagram is now trying to protect themselves from bots, so to disassemble it most interesting.
The task arose, to get the number of Posts, Followers, the Following on the user’s open profile.
This is what the HTML block code looks like, which contains this data in Instagram:

<ul class=" _3dEHb">
  <li class=" LH36I">
    <span class=" _81NM2">
      <span class="g47SY lOXF2">
        3
      </span> 
      posts
    </span>
  </li>
  <li class=" LH36I">
    <a class=" _81NM2" href="/username/followers/">
      <span class="g47SY lOXF2" title="153">
        153
      </span>
       followers
    </a>
  </li>
  <li class=" LH36I">
    <a class=" _81NM2" href="/username/following/">
      Following: 
      <span class="g47SY lOXF2">
        8
      </span>
    </a>
  </li>
</ul>

 
In total, we have three digits, which are represented in different ways, we use this code to get the data:

String posts=driver.findElement(By.xpath("//ul/li/span/span")).getText();
String followers=driver.findElement(By.xpath("//a[contains(@href,'followers')][1]//span")).getAttribute("title");
String following=driver.findElement(By.xpath("//a[contains(@href,'following')][1]//span")).getText();
System.out.println("Posts:     "+posts);
System.out.println("Followers: "+followers);
System.out.println("Following: "+following);

 
In order to get the number of posts:

<ul class=" _3dEHb">
  <li class=" LH36I">
    <span class=" _81NM2">
      <span class="g47SY lOXF2">
        3
.........

 
We use the XPath design://ul/li/span/span
We simply list the last nesting of the tree and as a result we get the contents-“3”

Next we will know the number of subscriptions:

.........
    <a class=" _81NM2" href="/username/followers/">
      <span class="g47SY lOXF2" title="153">
        153
      </span>
       followers
.........

 
//a[contains(@href,’followers’)][1]//span here we find the first encountered tag A, in href link of which, there is a substring followers, and take from it attributes of the span tag. The title attribute contains the number of subscribers. In the example, this number is 153.

Finally, we get the number of subscriptions:

.........
    <a class=" _81NM2" href="/username/following/">
      Подписки: 
      <span class="g47SY lOXF2">
        8
.........

 
//a[contains(@href,’following’)][1]//span  the same as in the second command, only the reference is searched for the occurrence of the following, and we are interested not the attribute, but the text, in this case 8.


The task was interesting, in the selection of the correct combination of XPath helped me online editors of XPath, none of them was not comfortable enough, so I can not recommend any one, but with them you can play with the XPath on a lot faster than Progonaya Options through the bot.

AJAX PHP JQUERY Transfer POST Request

In order to send a POST request to PHP script via JQUERY AJAX, create 2 files:

jqtest.htm – in which will be the request form and JavaScript code to generate and send the request;

jqtest.php – for receiving and sending the answer.

Listing of the file jqtest.htm:

<div>
<label for="request">Request:  </label>
<input id="request">
<input type="submit" value="Send" onclick="send();">
</div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
  function send()
  {
    jQuery.ajax({
      dataType: "json",
      method: "POST",
      url: "jqtest.php",
      data: { msg: jQuery('#request').val()}
    }).done(function( msg ) {
      alert(msg['answer']);
    });
  }
</script>

Listing of the file jqtest.php:

<?php
$q = ($_POST['msg']);
$ans= array(
  'answer' => 'You send: '.$q,
);
echo json_encode($ans);
?>

JQUERY query passes the MSG key in JSON format, and PHP code generates a JSON response and returns it in the answer key.

Cross-Origin Read Blocking (CORB)-Resolved

Each... You can listen, but not everyone is worth talking to.
Arthur Schendhauer

When you try to send a jQuery JSON request from another domain, you receive an error:

Access to XMLHttpRequest at ‘ http://* ‘ from Origin ‘ http://* ‘ has been blocked by CORS policy: No ‘ Access-Control-Allow-Origin ‘ header is present on the requested resource.

jquery. js? ver = *: 4 Cross-Origin Read Blocking (CORB) blocked cross-origin response * with MIME type application/JSON. See https://www.chromestatus.com/feature/5629709824032768 for more details. 

This means that sharing resources between different sources (CORS) is not allowed.

In order to allow CORS, it is necessary at the beginning of the PHP script, which processes the request, to add the generation of server response headers indicating that CORS is allowed.

<?php
switch ($ _server['HTTP_ORIGIN']) {
  Case 'http://remote.domain': Case 'https://remote.domain':
  Header ('Access-Control-Allow-Origin: '. $_server['HTTP_ORIGIN']);
  Header ('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
  Header ('Access-Control-Max-Age: 1000');
  Header ('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
  break;
}
?>
  • http://remote.domain-the URL of the site from which the request may occur.

On the client side, you need to specify crossDomain: true:

<script>
jQuery.ajax({
  crossDomain: true,
  dataType: "json",
  method: "POST",
  url: "http://main.domain/script.php",
  data: { key: "some text" }
  }).done(function( msg ) {
  // answer
});
</script>

So, to pass a request from one site to another, you need to specify the server headers that allow requests from a certain remote domain in the receiving site. And on the remote site, write a key that indicates that this query will work between different domains.

PgAdmin – How do I prevent updates from being checked? Decided.

PgAdmin 4 has already released version 3.3, which runs in the browser and runs crooked or slow.

The simplest and quickest solution to this problem, is to install the version 2.1, but in this case, each time you run this tool, the ToolTip pops up:

 Currently, you are using PgAdmin 4 version 2.1, but the current version is 3.3.

This message can be closed only by hands by clicking on the Cross.

So that this message does not appear Continue reading PgAdmin – How do I prevent updates from being checked? Decided.