<?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 Wordpress - soban</title>
	<atom:link href="https://soban.pl/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://soban.pl/category/wordpress/</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>
	</channel>
</rss>
