<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Archiwa Nginx - soban</title>
	<atom:link href="https://soban.pl/category/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>https://soban.pl/category/nginx/</link>
	<description>IT, Linux, Servers, Security</description>
	<lastBuildDate>Fri, 09 Feb 2024 13:53:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Proxy through nginx frontend to the second virtual server wordpress</title>
		<link>https://soban.pl/proxy-through-nginx-frontend-to-the-second-virtual-server-wordpress/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Sun, 07 Nov 2021 11:48:33 +0000</pubDate>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://soban.pl/?p=315</guid>

					<description><![CDATA[<p>In a situation where we have one public IP address and we have many domains directed to that IP address, it is worth considering spreading the traffic to other servers. Proxmox, which allows you to create a pair of virtual machines, is perfect in such a situation. In my case, each virtual machine is separated [&#8230;]</p>
<p>Artykuł <a href="https://soban.pl/proxy-through-nginx-frontend-to-the-second-virtual-server-wordpress/">Proxy through nginx frontend to the second virtual server wordpress</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In a situation where we have one public IP address and we have many domains directed to that IP address, it is worth considering spreading the traffic to other servers. Proxmox, which allows you to create a pair of virtual machines, is perfect in such a situation. In my case, each virtual machine is separated and the traffic is broken down by nginx, which distributes the traffic to other servers. The virtual machine on my website will redirect traffic, I have the IP address for wordpress: <strong>10.10.11.105 </strong>on port <strong>80</strong>. In this case, no encryption is required, but the frontend itself, which manages the traffic, will present itself with encryption and security on port <strong>443</strong>.</p>



<p>Two machines with the following configuration will participate throughout the process:<br><strong>up-page</strong> IP: <strong>10.10.14.200</strong><br><strong>soban-pl</strong> IP: <strong>10.10.11.105</strong></p>



<p>So let&#8217;s move on to the frontend that distributes traffic to other machines.<br>The frontend is done by linux debian 11 (bullseye), in addition, I have the following entry in the repository (<strong>/etc/apt/sources.list</strong>):</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#...
deb http://nginx.org/packages/debian/ bullseye nginx
deb-src http://nginx.org/packages/debian/ bullseye nginx</pre></div>



<p>To install nginx, run the following commands:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># apt update
# apt install nginx</pre></div>



<p>You should make sure that the traffic from the frontend has the appropriate port 80 transitions. You can read how to check the network transitions here: <strong><a href="https://soban.pl/check-network-connection-and-open-tcp-port-via-netcat/" target="_blank" rel="noreferrer noopener">Check network connection and open TCP port via netcat</a></strong>.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="469" height="154" src="https://soban.pl/wp-content/uploads/2021/11/image-18.png" alt="Screenshot of a terminal window showing a successful telnet connection to the IP address 10.10.11.105 on port 80, followed by the user exiting the telnet session with the 'quit' command." class="wp-image-317" srcset="https://soban.pl/wp-content/uploads/2021/11/image-18.png 469w, https://soban.pl/wp-content/uploads/2021/11/image-18-300x99.png 300w" sizes="(max-width: 469px) 100vw, 469px" /></figure>



<p>The configuration of the frontend that distributes the traffic is as follows (<strong>/etc/nginx/conf.d/soban.pl.ssl.conf</strong>):</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">upstream soban-pl-webservers {
    server 10.10.11.105:80;
}

server {
    if ($host = www.soban.pl) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = soban.pl) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name soban.pl www.soban.pl;
        return 301 https://soban.pl$request_uri;
}

server {
    listen 443 ssl http2;
    server_name  www.soban.pl;
    ssl_certificate /etc/letsencrypt/live/www.soban.pl/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.soban.pl/privkey.pem; # managed by Certbot
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    return 301 https://soban.pl$request_uri;
}

server {
    listen 443 ssl http2;
    server_name  soban.pl _;
    ssl_certificate /etc/letsencrypt/live/soban.pl/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/soban.pl/privkey.pem; # managed by Certbot
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
}

    location / {
        access_log /var/log/nginx/access-soban.pl.log;
        error_log /var/log/nginx/error-soban.pl.log;
        proxy_pass http://soban-pl-webservers;
        proxy_redirect https://soban-pl-webservers http://soban-pl-webservers;
        expires off;

        proxy_read_timeout       3500;
        proxy_connect_timeout    3250;

        proxy_set_header   X-Real-IP          $remote_addr;
        proxy_set_header   Host               $host;
        proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto  https;
        proxy_set_header   SSL_PROTOCOL $ssl_protocol;
        proxy_set_header   SSL_CLIENT_CERT $ssl_client_cert;
        proxy_set_header   SSL_CLIENT_VERIFY $ssl_client_verify;
        proxy_set_header   SSL_SERVER_S_DN $ssl_client_s_dn;

                proxy_set_header X-Scheme $scheme;
                proxy_ssl_session_reuse off;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
    }
      location ~ ^/(wp-admin|wp-login\.php) {
            auth_basic "Restricted";
            auth_basic_user_file /etc/nginx/conf.d/htpasswd;
           proxy_pass http://soban-pl-webservers;
           proxy_redirect https://soban-pl-webservers http://soban-pl-webservers;
           expires off;
           proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
           proxy_set_header        Host            $host;
           proxy_set_header        X-Real-IP       $remote_addr;
           proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }

}</pre></div>



<p>Configuration of the above-mentioned wordpress, additional authorization is also set when you try to log in to wp-admin, you can read about it here: <strong><a href="https://soban.pl/more-security-wp-admin-in-nginx/" target="_blank" rel="noreferrer noopener">More security wp-admin in nginx</a></strong>. </p>



<p>In the next step, check if the nginx configuration is correct by: </p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service nginx configtest</pre></div>



<figure class="wp-block-image size-full"><img decoding="async" width="808" height="76" src="https://soban.pl/wp-content/uploads/2021/11/image-17.png" alt="Terminal output displaying a successful nginx configuration test with the messages: 'nginx: the configuration file /etc/nginx/nginx.conf syntax is ok' and 'nginx: configuration file /etc/nginx/nginx.conf test is successful'." class="wp-image-316" srcset="https://soban.pl/wp-content/uploads/2021/11/image-17.png 808w, https://soban.pl/wp-content/uploads/2021/11/image-17-300x28.png 300w, https://soban.pl/wp-content/uploads/2021/11/image-17-768x72.png 768w" sizes="(max-width: 808px) 100vw, 808px" /></figure>



<p>If everything is fine, restart nginx:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service nginx restart</pre></div>



<p>In a virtual machine with nginx it should also be installed. This is the same as debian linux 11 (bullseye), so the respository should look like this:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#...
deb http://nginx.org/packages/debian/ bullseye nginx
deb-src http://nginx.org/packages/debian/ bullseye nginx</pre></div>



<p>Just installing nginx looks the same as on a machine that acts as a proxy.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># apt update
# apt install nginx</pre></div>



<p>All configuration is in <strong>/etc/nginx/conf.d/soban.pl.conf</strong>:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">server {
    listen   80;

   client_max_body_size 20M;

    server_name soban.pl www.soban.pl;
    access_log /var/log/nginx/access-soban.pl.log; #access logi
    error_log /var/log/nginx/error-soban.log; # error logi
    port_in_redirect off;
    set_real_ip_from  10.10.11.105;
    real_ip_header    X-Forwarded-For;
    real_ip_recursive on;
       root /home/produkcja/wordpress/;
       index index.html index.php;

if ($host ~* ^www\.(.*))
{
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}

    error_page 404 /index.php;


        location ~ \.php$ {
                root /home/produkcja/wordpress/; # dir where is wordpress
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        }

        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location = /sitemap.xml {
                rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
                rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
                rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
                rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
       }

location = /favicon.ico {
  return 204;
  access_log     off;
  log_not_found  off;
}

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
        }location ~* \.(pdf)$ {
expires 30d;
}

}</pre></div>



<p>Also in this case, check the correctness of the nginx service configuration:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service nginx configtest</pre></div>



<figure class="wp-block-image size-full"><img decoding="async" width="802" height="66" src="https://soban.pl/wp-content/uploads/2021/11/image-19.png" alt="" class="wp-image-318" srcset="https://soban.pl/wp-content/uploads/2021/11/image-19.png 802w, https://soban.pl/wp-content/uploads/2021/11/image-19-300x25.png 300w, https://soban.pl/wp-content/uploads/2021/11/image-19-768x63.png 768w" sizes="(max-width: 802px) 100vw, 802px" /></figure>



<p>Everything looks fine, so let&#8217;s move on to restarting the service:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service nginx restart</pre></div>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="806" height="71" src="https://soban.pl/wp-content/uploads/2021/11/image-20.png" alt="" class="wp-image-319" srcset="https://soban.pl/wp-content/uploads/2021/11/image-20.png 806w, https://soban.pl/wp-content/uploads/2021/11/image-20-300x26.png 300w, https://soban.pl/wp-content/uploads/2021/11/image-20-768x68.png 768w" sizes="auto, (max-width: 806px) 100vw, 806px" /></figure>



<p>If the whole configuration was done correctly, the page should be directed without encrypted traffic to the virtual machine with wordpress. A wordpress service with nginx is not the only one that can be hosted or proxied. We can direct traffic from nginx to e.g. jboss, apacha and all other web services. Of course, this requires a corresponding modification of the configuration presented above, but the general outline of the concept as an nginx proxy has been presented. You should also remember about the appropriate configuration of keys and certificates. In my case let&#8217;s encrypt works perfectly for this.</p>
<p>Artykuł <a href="https://soban.pl/proxy-through-nginx-frontend-to-the-second-virtual-server-wordpress/">Proxy through nginx frontend to the second virtual server wordpress</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>More security wp-admin in nginx</title>
		<link>https://soban.pl/more-security-wp-admin-in-nginx/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Thu, 21 Oct 2021 16:44:39 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://soban.pl/?p=229</guid>

					<description><![CDATA[<p>Some time ago I noticed that my wordpress hacks are being hacked by logging into the backend of the website. A bot or a hacker is trying to do this using a set of passwords. I decided to secure the website&#8217;s backend by requiring additional authentication. In nginxe we can set this up by: We [&#8230;]</p>
<p>Artykuł <a href="https://soban.pl/more-security-wp-admin-in-nginx/">More security wp-admin in nginx</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Some time ago I noticed that my wordpress hacks are being hacked by logging into the backend of the website. A bot or a hacker is trying to do this using a set of passwords. I decided to secure the website&#8217;s backend by requiring additional authentication. In nginxe we can set this up by:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">location ~ ^/(wp-admin|wp-login\.php) {
           auth_basic "Restricted";
           auth_basic_user_file /etc/nginx/.htpasswd;
           proxy_pass http://upstream-webservers;
           proxy_redirect https://upstream-webservers http://upstream-webservers;
           expires off;
           proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
           proxy_set_header        Host            $host;
           proxy_set_header        X-Real-IP       $remote_addr;
           proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }</pre></div>



<p>We still need to provide the username for authorization and save to the file (/etc/nginx/.htpasswd) as we entered in the nginx configuration file. In &#8220;my_user_name&#8221;, replace the login of the user with which we will be authorized.:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># echo -n 'my_user_name:' &gt;&gt; /etc/nginx/.htpasswd</pre></div>



<p> And the encrypted password has been set by openssl:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># openssl passwd -apr1 &gt;&gt; /etc/nginx/.htpasswd</pre></div>



<p>Openssl will ask you to come up with a password and enter it twice:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="809" height="71" src="https://soban.pl/wp-content/uploads/2021/10/image-76.png" alt="" class="wp-image-232" srcset="https://soban.pl/wp-content/uploads/2021/10/image-76.png 809w, https://soban.pl/wp-content/uploads/2021/10/image-76-300x26.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-76-768x67.png 768w" sizes="auto, (max-width: 809px) 100vw, 809px" /></figure>



<p>As a result, we will get a file with an encrypted password:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="612" height="50" src="https://soban.pl/wp-content/uploads/2021/10/image-77.png" alt="" class="wp-image-233" srcset="https://soban.pl/wp-content/uploads/2021/10/image-77.png 612w, https://soban.pl/wp-content/uploads/2021/10/image-77-300x25.png 300w" sizes="auto, (max-width: 612px) 100vw, 612px" /></figure>



<p>Before reloading nginx, we do a configuration verification:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service nginx configtest</pre></div>



<p>If everything is set correctly, we should receive the following message:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="811" height="83" src="https://soban.pl/wp-content/uploads/2021/10/image-81.png" alt="" class="wp-image-240" srcset="https://soban.pl/wp-content/uploads/2021/10/image-81.png 811w, https://soban.pl/wp-content/uploads/2021/10/image-81-300x31.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-81-768x79.png 768w" sizes="auto, (max-width: 811px) 100vw, 811px" /></figure>



<p>Now we can restart the service nginx:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service nginx restart</pre></div>



<p>The final verification will be to log in to the backend (e.g. www.example-page-wordpress.pl/<strong>wp-admin</strong>/), as a result, we should be asked for the login and password that we created above:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="738" height="458" src="https://soban.pl/wp-content/uploads/2021/10/image-79.png" alt="" class="wp-image-235" srcset="https://soban.pl/wp-content/uploads/2021/10/image-79.png 738w, https://soban.pl/wp-content/uploads/2021/10/image-79-300x186.png 300w" sizes="auto, (max-width: 738px) 100vw, 738px" /></figure>



<p>This is a simple trick to protect your wordpress from bot attacks. However, it should be remembered that we do not share passwords with anyone and setting default usernames and simple passwords is asking for a problem.</p>
<p>Artykuł <a href="https://soban.pl/more-security-wp-admin-in-nginx/">More security wp-admin in nginx</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Useful tricks to view and search logs</title>
		<link>https://soban.pl/useful-tricks-to-view-and-search-logs/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Thu, 21 Oct 2021 13:12:36 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">https://soban.pl/?p=216</guid>

					<description><![CDATA[<p>It often happens that we have to catch a given message, e.g. &#8220;error&#8221; while browsing the logs. Alternatively, we look for the occurrence of a given phrase in the old files. Both &#8220;tail&#8221; and &#8220;grep&#8221; are very useful for this. Especially if the logs are set in verbal mode, where there is a lot of [&#8230;]</p>
<p>Artykuł <a href="https://soban.pl/useful-tricks-to-view-and-search-logs/">Useful tricks to view and search logs</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>It often happens that we have to catch a given message, e.g. &#8220;<strong>error</strong>&#8221; while browsing the logs. Alternatively, we look for the occurrence of a given phrase in the old files. Both &#8220;<strong>tail</strong>&#8221; and &#8220;<strong>grep</strong>&#8221; are very useful for this. Especially if the logs are set in verbal mode, where there is a lot of messages in the log. We can also exclude certain phrases after parsing the information set. It is enough to use grep properly.</p>



<p>Let&#8217;s start by looking at all nginx logs.</p>



<p>In this case, sorting from oldest to newest is very useful as we know where to find the newest log entries:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># cd /var/log/nginx/
# ls -ltr *</pre></div>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="832" height="622" src="https://soban.pl/wp-content/uploads/2021/10/image-75.png" alt="" class="wp-image-224" srcset="https://soban.pl/wp-content/uploads/2021/10/image-75.png 832w, https://soban.pl/wp-content/uploads/2021/10/image-75-300x224.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-75-768x574.png 768w" sizes="auto, (max-width: 832px) 100vw, 832px" /></figure>



<p>If we are interested in the latest data, we will focus on the access-soban.pl.log file.</p>



<p>I know that my website is monitored by <a href="https://uptimerobot.com/" target="_blank" rel="noreferrer noopener">uptimerobot.com</a> and I would like to find out, for example, from what IP address the website gets a query, e.g. to add it to the firewall as trusted:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep -i uptime access-soban.pl.log</pre></div>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="994" height="395" src="https://soban.pl/wp-content/uploads/2021/10/image-71.png" alt="" class="wp-image-219" srcset="https://soban.pl/wp-content/uploads/2021/10/image-71.png 994w, https://soban.pl/wp-content/uploads/2021/10/image-71-300x119.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-71-768x305.png 768w" sizes="auto, (max-width: 994px) 100vw, 994px" /></figure>



<p>As you can see, in this case, the bot that is querying the server has the IP address: <strong>208.115.191.21</strong>. If I wanted to see all calls from this IP address, I could view them this way:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep 208.115.199.21 access-soban.pl.log* | less</pre></div>



<p>If I press (<strong>shift + g</strong>) I&#8217;ll go to the bottom of the log:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="668" src="https://soban.pl/wp-content/uploads/2021/10/image-72-1024x668.png" alt="" class="wp-image-220" srcset="https://soban.pl/wp-content/uploads/2021/10/image-72-1024x668.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-72-300x196.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-72-768x501.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-72.png 1132w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>It is worth noting that in this case the file in which the query is located is also given.</p>



<p>Now suppose I would like the logs, but without the &#8220;<strong>uptimerobot</strong>&#8220;:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep -v uptimerobot access-soban.pl.log* | less</pre></div>



<p>This way all queries containing the word &#8220;uptimerobots&#8221; were cut. We can of course diminish the output from the console more by adding &#8220;<strong>| grep -v</strong>&#8221; possibly. Let&#8217;s cut out &#8220;<strong>sitemap</strong>&#8220;:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep -v uptimerobot access-soban.pl.log* | grep -v sitemap | less</pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="693" src="https://soban.pl/wp-content/uploads/2021/10/image-73-1024x693.png" alt="" class="wp-image-221" srcset="https://soban.pl/wp-content/uploads/2021/10/image-73-1024x693.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-73-300x203.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-73-768x520.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-73.png 1117w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>One handy thing is to direct the stream from the console output to a file. We do this as follows &#8220;<strong>/tmp/file.log</strong>&#8220;:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep -v uptimerobot access-soban.pl.log | grep -v sitemap &gt;&gt; /tmp/file.log</pre></div>



<p>Additionally, we can pack the file:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># tar -zcf /tmp/file.log.tar.gz /tmp/file.log</pre></div>



<p>After packing the file, we can send it to another person. Sensitive data, such as inquiries or logins, can be cut using grep, as we did above.</p>



<p>Now let&#8217;s move on to one of the most useful tools for watching live what happens when someone enters a page:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># tail -f *.log</pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="217" src="https://soban.pl/wp-content/uploads/2021/10/image-74-1024x217.png" alt="" class="wp-image-222" srcset="https://soban.pl/wp-content/uploads/2021/10/image-74-1024x217.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-74-300x64.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-74-768x163.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-74.png 1130w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>At this point it is worth noting that we &#8220;caught&#8221; the logs from the files: &#8220;access-soban.pl.log&#8221; and &#8220;error-soban.pl.log&#8221;. However, the &#8220;error-soban.pl.log&#8221; log is empty, so its content is not shown below. However, if something came up, we would see the contents of the updated file on the console.</p>



<p>Useful at this point is to combine grep and tail. We&#8217;re assuming we don&#8217;t want uptimerobots to bump into our consoles while observing the logs, so we&#8217;re going to cut them like this:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># tail -f *.log | grep -v uptimerobots</pre></div>



<p>The given examples can be modified in any way. I encourage you to use it in various combinations of tail and grep, especially in situations where erros/warning are repeated. Of course, not only in nginx logs you can use these commands. In all logs where we operate on text, be it system or application. Passing the text mentioned above is very helpful.</p>
<p>Artykuł <a href="https://soban.pl/useful-tricks-to-view-and-search-logs/">Useful tricks to view and search logs</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Upgrade Debian GNU/Linux 10 (buster) to 11 (bullseye)</title>
		<link>https://soban.pl/upgrade-debian-gnu-linux-10-buster-to-11-bullseye/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Fri, 01 Oct 2021 13:26:37 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Patching]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://soban.pl/?p=42</guid>

					<description><![CDATA[<p>Before we start upgrading the Debian system version, please make a snapshot or a possible backup of the system. Such a change entails significant changes that can damage the system. Of course, before you upgrade the system in production, it is best to upgrade to the testing environment first. The upgrade process affects the entire [&#8230;]</p>
<p>Artykuł <a href="https://soban.pl/upgrade-debian-gnu-linux-10-buster-to-11-bullseye/">Upgrade Debian GNU/Linux 10 (buster) to 11 (bullseye)</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Before we start upgrading the Debian system version, please make a snapshot or a possible backup of the system. Such a change entails significant changes that can damage the system. Of course, before you upgrade the system in production, it is best to upgrade to the testing environment first. The upgrade process affects the entire system. Services may not be available at this time. If the system is doing the hosting for your website then it may not be available!<br><br>Always bear in mind that the production environment is different from test environment, so I recommend that you do it carefully. A good practice is to keep a time interval between the upgrade of test and production environment, in my case it is a week. Remember not to make changes to production on Friday!<br><br>This is how we check the version of the system:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="870" height="364" src="https://soban.pl/wp-content/uploads/2021/10/image.png" alt="" class="wp-image-45" srcset="https://soban.pl/wp-content/uploads/2021/10/image.png 870w, https://soban.pl/wp-content/uploads/2021/10/image-300x126.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-768x321.png 768w" sizes="auto, (max-width: 870px) 100vw, 870px" /></figure>



<p>And now, we going to update OS, but before we do that &#8211; we will make copy of:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">cp /etc/apt/sources.list /root/sources.list_buster</pre></div>



<p>There is sorces setup for buster:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># cat /etc/apt/sources.list
deb http://ftp.debian.org/debian buster main contrib
deb http://ftp.debian.org/debian buster-updates main contrib
deb http://security.debian.org buster/updates main contrib
deb http://nginx.org/packages/debian/ buster nginx
deb-src http://nginx.org/packages/debian/ buster nginx</pre></div>



<p>Before we upgrade the debian system version to 11, we need to do a full upgrade:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># apt update &amp;&amp; apt upgrade -q -y &amp;&amp; apt dist-upgrade -q -y &amp;&amp; apt autoremove -y -q</pre></div>



<p>Then we use sed to replace &#8220;buster&#8221; on &#8220;bullseye&#8221;:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># sed -i 's/buster/bullseye/g' /etc/apt/sources.list</pre></div>



<p>There here&#8217;s the effect:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># cat /etc/apt/sources.list</pre></div>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="769" height="128" src="https://soban.pl/wp-content/uploads/2021/10/image-25.png" alt="" class="wp-image-114" srcset="https://soban.pl/wp-content/uploads/2021/10/image-25.png 769w, https://soban.pl/wp-content/uploads/2021/10/image-25-300x50.png 300w" sizes="auto, (max-width: 769px) 100vw, 769px" /></figure>



<p>To be sure, we will do a comparison of the backed up file:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="346" src="https://soban.pl/wp-content/uploads/2021/10/image-2-1024x346.png" alt="" class="wp-image-48" srcset="https://soban.pl/wp-content/uploads/2021/10/image-2-1024x346.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-2-300x101.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-2-768x260.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-2.png 1156w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>And then we can do update:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># apt update &amp;&amp; apt upgrade -q -y &amp;&amp; apt dist-upgrade -q -y &amp;&amp; apt autoremove -y -q</pre></div>



<p><br>So that it is not too easy, to start the task in the form of:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="186" src="https://soban.pl/wp-content/uploads/2021/10/image-1-1024x186.png" alt="" class="wp-image-47" srcset="https://soban.pl/wp-content/uploads/2021/10/image-1-1024x186.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-1-300x55.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-1-768x140.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-1.png 1094w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p><br>Specifically about this error:</p>



<pre class="wp-block-preformatted">Err:5 http://security.debian.org bullseye/updates Release
  404  Not Found [IP: 199.232.150.132 80]
Reading package lists... Done
E: The repository 'http://security.debian.org bullseye/updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.</pre>



<p>To fix it, use any editor on the file (vi in ​​my case):</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># vi /etc/apt/sources.list</pre></div>



<p>We remove line 4 &#8211; &#8220;deb http://security.debian.org buster/updates main contrib&#8221; as you can see, we go out and save :</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="378" src="https://soban.pl/wp-content/uploads/2021/10/image-3-1024x378.png" alt="" class="wp-image-49" srcset="https://soban.pl/wp-content/uploads/2021/10/image-3-1024x378.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-3-300x111.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-3-768x284.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-3.png 1123w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Of course, any other editor like nano is also good for this case.<br>The contents of the /etc/apt/sources.list file now looks like this:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># cat /etc/apt/sources.list
deb http://ftp.debian.org/debian bullseye main contrib
deb http://ftp.debian.org/debian bullseye-updates main contrib
deb http://nginx.org/packages/debian/ bullseye nginx
deb-src http://nginx.org/packages/debian/ bullseye nginx</pre></div>



<p>We can try to update the system again:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># apt update &amp;&amp; apt upgrade -q -y &amp;&amp; apt dist-upgrade -q -y &amp;&amp; apt autoremove -y -q</pre></div>



<p>Now you need get some the system upgrade process has started. You can go for a coffee, or not 😉<br>There will be questions.<br>And more information, albout apt listchanges:<br></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="944" height="904" src="https://soban.pl/wp-content/uploads/2021/10/image-6.png" alt="" class="wp-image-54" srcset="https://soban.pl/wp-content/uploads/2021/10/image-6.png 944w, https://soban.pl/wp-content/uploads/2021/10/image-6-300x287.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-6-768x735.png 768w" sizes="auto, (max-width: 944px) 100vw, 944px" /></figure>



<p>Just press &#8216;q&#8217; and enter.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="166" src="https://soban.pl/wp-content/uploads/2021/10/image-4-1024x166.png" alt="" class="wp-image-51" srcset="https://soban.pl/wp-content/uploads/2021/10/image-4-1024x166.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-4-300x49.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-4-768x124.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-4-1536x248.png 1536w, https://soban.pl/wp-content/uploads/2021/10/image-4.png 1917w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>In this case we press enter.</p>



<p>Services to restart:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="194" src="https://soban.pl/wp-content/uploads/2021/10/image-8-1024x194.png" alt="" class="wp-image-56" srcset="https://soban.pl/wp-content/uploads/2021/10/image-8-1024x194.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-8-300x57.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-8-768x146.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-8-1536x291.png 1536w, https://soban.pl/wp-content/uploads/2021/10/image-8.png 1915w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Enter agien.</p>



<p>This is question, about ssh deamon configuration:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="247" src="https://soban.pl/wp-content/uploads/2021/10/image-9-1024x247.png" alt="" class="wp-image-57" srcset="https://soban.pl/wp-content/uploads/2021/10/image-9-1024x247.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-9-300x72.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-9-768x185.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-9-1536x370.png 1536w, https://soban.pl/wp-content/uploads/2021/10/image-9.png 1905w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>In my case, I press enter because I don&#8217;t want to make changes to its configuration.</p>



<p><br>If all went well, we can reboot the system:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># reboot</pre></div>



<p>Now check the system:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="621" height="222" src="https://soban.pl/wp-content/uploads/2021/10/image-11.png" alt="" class="wp-image-60" srcset="https://soban.pl/wp-content/uploads/2021/10/image-11.png 621w, https://soban.pl/wp-content/uploads/2021/10/image-11-300x107.png 300w" sizes="auto, (max-width: 621px) 100vw, 621px" /></figure>



<p>Congratulations, we are on the new version of the system!<br>At this point, we can verify all services, for example whether the website is working properly. If it is OK, upgrade the production environment.<br><br>In my cases, I have problem PHP new version.<br>PHP have no persmision on nginx to user &#8211; when I try enter to page:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># tail -f /var/log/nginx/error-*.log 
unix:/var/run/php/php-fpm.sock failed (13: Permission denied)</pre></div>



<p>So we need to fix that in this way:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service php7.4-fpm status
* php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-10-01 14:59:14 CEST; 3min 28s ago
       Docs: man:php-fpm7.4(8)
    Process: 289 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/S&gt;
   Main PID: 116 (php-fpm7.4)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
        CPU: 364ms
     CGroup: /system.slice/php7.4-fpm.service
             |-116 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             |-287 php-fpm: pool www
             `-288 php-fpm: pool www

Oct 01 14:59:11 soban-pl systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Oct 01 14:59:14 soban-pl systemd[1]: Started The PHP 7.4 FastCGI Process Manager.</pre></div>



<p>There is something wrong with the permissions:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep www-data /etc/php/7.4/fpm/pool.d/www.conf
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data</pre></div>



<p>Let&#8217;s make some backup:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/www.conf.backup.$(date +%F)</pre></div>



<p>I will replace www-data to nginx:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># sed -i 's/www-data/nginx/g' /etc/php/7.4/fpm/pool.d/www.conf</pre></div>



<p>Now it&#8217;s looks better:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># grep nginx /etc/php/7.4/fpm/pool.d/www.conf
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx</pre></div>



<p>And restart services:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># service php7.4-fpm restart</pre></div>



<p>Also checking status:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="195" src="https://soban.pl/wp-content/uploads/2021/10/image-10-1024x195.png" alt="" class="wp-image-58" srcset="https://soban.pl/wp-content/uploads/2021/10/image-10-1024x195.png 1024w, https://soban.pl/wp-content/uploads/2021/10/image-10-300x57.png 300w, https://soban.pl/wp-content/uploads/2021/10/image-10-768x146.png 768w, https://soban.pl/wp-content/uploads/2021/10/image-10-1536x292.png 1536w, https://soban.pl/wp-content/uploads/2021/10/image-10.png 1915w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Another problem is that, mariadb was removed, so I install it agien:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag"># apt-get install mariadb-server mariadb-client -y</pre></div>



<p>and that resolved all my problems.</p>



<p>To be 100% sure, I reloaded the entire machine.</p>
<p>Artykuł <a href="https://soban.pl/upgrade-debian-gnu-linux-10-buster-to-11-bullseye/">Upgrade Debian GNU/Linux 10 (buster) to 11 (bullseye)</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Expired domain nginx</title>
		<link>https://soban.pl/nginx-check-domain-expiring-script/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Mon, 27 Sep 2021 17:41:00 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://soban.pl/?p=1</guid>

					<description><![CDATA[<p>Script to help check if the domain is expiring (don&#8217;t forget change e-mail in script &#8211; now is soban@soban.pl): This way you can download the script and give it permission to run: And now we can add it to crontab, on monday for example:</p>
<p>Artykuł <a href="https://soban.pl/nginx-check-domain-expiring-script/">Expired domain nginx</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Script to help check if the domain is expiring (don&#8217;t forget change e-mail in script &#8211; now is soban@soban.pl):</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">$ cat /root/check_domain.sh
#!/bin/bash
# Domain name list - add your domainname here
email=soban@soban.pl
DOM=`grep server_name /etc/nginx/conf.d/* | awk '{print $3}' | sed 's/\.$//'`
DOMAIN=`ls /etc/nginx/conf.d/ | sed -e 's/\&lt;conf\&gt;//g' | sed -e 's/\&lt;ssl\&gt;//g' | sed 's/\.$//' | sed 's/\.$//' &amp;&amp; echo -e $DOM | sed 's/\;/''/g'`
DOM=`echo -e $DOMAIN | tr ' ' '\n' | sed 's/\;/''/g'| sort -u`
for d in $DOM
do
  date_exp=`whois $d  | egrep [0-9] | egrep -i 'Expiry|renewal|Expiration' | tr '.' "-" | head -1 | sed 's/^[^:]*://g' | awk '{print $1}'`
  if [ ! -z "$date_exp" ]; then
    left=`echo $(expr '(' $(date -d $date_exp +%s) - $(date +%s) + 86399 ')' / 86400)`
    echo "$d - `date -d $date_exp +%F` - $left days until expiration"
        if (( $left &lt; 30 )); then
          echo "$d - `date -d $date_exp +%F` - $left days until expiration" |  mail -s "$d - DOMAIN EXPIRES!!" $email
        fi
  fi
  sleep 300
done</pre></div>



<p>This way you can download the script and give it permission to run:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">$ cd /root/
$ wget https://soban.pl/bash/check_domain.sh
$ chmod +x check_domain.sh</pre></div>



<p>And now we can add it to crontab, on monday for example:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">$ crontab -e
# checking domains every Monday
00 08 * * 1 date &gt;&gt; /root/expiring_domain &amp;&amp; /root/check_domain.sh &gt;&gt; /root/expiring_domain</pre></div>
<p>Artykuł <a href="https://soban.pl/nginx-check-domain-expiring-script/">Expired domain nginx</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
