<?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>Server &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/server/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Sat, 08 Jun 2024 14:59:58 +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>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Server &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>NordVPN: Extracting WireGuard Configuration</title>
		<link>https://myshittycode.com/2024/06/08/nordvpn-extracting-wireguard-configuration/</link>
					<comments>https://myshittycode.com/2024/06/08/nordvpn-extracting-wireguard-configuration/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Sat, 08 Jun 2024 14:59:51 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[GL.iNet]]></category>
		<category><![CDATA[NordVPN]]></category>
		<category><![CDATA[Travel Router]]></category>
		<category><![CDATA[VPN]]></category>
		<category><![CDATA[WireGuard]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=2604</guid>

					<description><![CDATA[<p>This article shows how to extract the WireGuard configuration from NordVPN without additional tools and test it by configuring WireGuard on a GL.iNet travel router (ex: Beryl AX). Why WireGuard? While most modern routers support OpenVPN and WireGuard protocols, the latter is faster and more efficient when traveling through the encrypted tunnels, providing a superior [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2024/06/08/nordvpn-extracting-wireguard-configuration/">NordVPN: Extracting WireGuard Configuration</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This article shows how to extract the WireGuard configuration from NordVPN without additional tools and test it by configuring WireGuard on a GL.iNet travel router (ex: Beryl AX).</p>



<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#why-wire-guard">Why WireGuard?</a></li><li><a href="#why-this-extra-step-when-using-nord-vpn">Why This Extra Step When Using NordVPN?</a></li><li><a href="#prerequisites">Prerequisites</a></li><li><a href="#step-1-generate-access-token-in-nord-vpn">Step 1: Generate Access Token in NordVPN</a></li><li><a href="#step-2-use-nord-vpn-ap-is-to-extract-wire-guard-configuration">Step 2: Use NordVPN APIs to Extract WireGuard Configuration</a></li><li><a href="#step-3-configure-wire-guard-on-router">Step 3: Configure WireGuard on Router</a></li></ul></nav></div>



<h2 class="wp-block-heading" id="why-wire-guard">Why WireGuard?</h2>



<p>While most modern routers support OpenVPN and WireGuard protocols, the latter is faster and more efficient when traveling through the encrypted tunnels, providing a superior VPN experience.</p>



<h2 class="wp-block-heading" id="why-this-extra-step-when-using-nord-vpn">Why This Extra Step When Using NordVPN?</h2>



<p>Unlike other VPN providers, NordVPN builds its proprietary solution, NordLynx, on WireGuard. Thus, it is not possible to configure it directly on your router unless you want to rely on the slower OpenVPN.</p>



<h2 class="wp-block-heading" id="prerequisites">Prerequisites</h2>



<ul class="wp-block-list">
<li>A NordVPN customer.</li>



<li>A router that supports WireGuard VPN protocol.</li>



<li>An environment to run Linux commands. Install <a href="https://jqlang.github.io/jq/download/" target="_blank" rel="noopener">jq</a> if it doesn&#8217;t exist.</li>



<li>Expert in CMD/CTRL+C and CMD/CTRL+V.</li>
</ul>



<h2 class="wp-block-heading" id="step-1-generate-access-token-in-nord-vpn">Step 1: Generate Access Token in NordVPN</h2>



<ul class="wp-block-list">
<li>Go to <a href="https://my.nordaccount.com/dashboard/nordvpn/manual-configuration/" target="_blank" rel="noreferrer noopener">this NordVPN link</a>.</li>



<li>Click on the <strong>Set up NordVPN manually</strong> button<strong>.</strong></li>
</ul>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="610" height="296" src="https://myshittycode.com/wp-content/uploads/2024/06/1-nordvpn-manual-setup.png?x45560" alt="" class="wp-image-2605" srcset="https://myshittycode.com/wp-content/uploads/2024/06/1-nordvpn-manual-setup.png 610w, https://myshittycode.com/wp-content/uploads/2024/06/1-nordvpn-manual-setup-300x146.png 300w" sizes="(max-width: 610px) 100vw, 610px" /></figure>



<ul class="wp-block-list">
<li>After completing the email verification, you will land on a page that allows you to generate an access token. Click on the <strong>Generate new token</strong> button.</li>
</ul>



<figure class="wp-block-image size-full"><img decoding="async" width="605" height="542" src="https://myshittycode.com/wp-content/uploads/2024/06/2-nordvpn-generate-new-token.png?x45560" alt="" class="wp-image-2606" srcset="https://myshittycode.com/wp-content/uploads/2024/06/2-nordvpn-generate-new-token.png 605w, https://myshittycode.com/wp-content/uploads/2024/06/2-nordvpn-generate-new-token-300x269.png 300w" sizes="(max-width: 605px) 100vw, 605px" /></figure>



<ul class="wp-block-list">
<li>Leave the token expiration as is. Click on the <strong>Generate token</strong> button.</li>
</ul>



<figure class="wp-block-image size-full"><img decoding="async" width="682" height="329" src="https://myshittycode.com/wp-content/uploads/2024/06/3-nordvpn-generate-token.png?x45560" alt="" class="wp-image-2608" srcset="https://myshittycode.com/wp-content/uploads/2024/06/3-nordvpn-generate-token.png 682w, https://myshittycode.com/wp-content/uploads/2024/06/3-nordvpn-generate-token-300x145.png 300w" sizes="(max-width: 682px) 100vw, 682px" /></figure>



<ul class="wp-block-list">
<li>Copy the access token to a text file and close the pop-up dialog.</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="680" height="338" src="https://myshittycode.com/wp-content/uploads/2024/06/4-nordvpn-copy-access-token.png?x45560" alt="" class="wp-image-2609" srcset="https://myshittycode.com/wp-content/uploads/2024/06/4-nordvpn-copy-access-token.png 680w, https://myshittycode.com/wp-content/uploads/2024/06/4-nordvpn-copy-access-token-300x149.png 300w" sizes="auto, (max-width: 680px) 100vw, 680px" /></figure>



<h2 class="wp-block-heading" id="step-2-use-nord-vpn-ap-is-to-extract-wire-guard-configuration">Step 2: Use NordVPN APIs to Extract WireGuard Configuration</h2>



<p>Fortunately, NordVPN provides a helpful Rest API that returns a list of recommended servers based on your current location. We can use this to query for a list of WireGuard-compatible servers.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#!/usr/bin/env bash

ACCESS_TOKEN=&quot;&#x5B;YOUR-ACCESS-TOKEN]&quot;
TOTAL_CONFIGS=3
DNS=&quot;1.1.1.1&quot;

CREDENTIALS_URL=&quot;https://api.nordvpn.com/v1/users/services/credentials&quot;
SERVER_RECOMMENDATIONS_URL=&quot;https://api.nordvpn.com/v1/servers/recommendations?&amp;filters\&#x5B;servers_technologies\]\&#x5B;identifier\]=wireguard_udp&amp;limit=$TOTAL_CONFIGS&quot;

PRIVATE_KEY=$(curl -s -u token:&quot;$ACCESS_TOKEN&quot; &quot;$CREDENTIALS_URL&quot; | jq -r .nordlynx_private_key)

curl -s &quot;$SERVER_RECOMMENDATIONS_URL&quot; | \
  jq -r --arg private_key &quot;$PRIVATE_KEY&quot; --arg dns &quot;$DNS&quot; &#039;
    .&#x5B;] |
    {
      filename: (.locations&#x5B;0].country.name + &quot; - &quot; + .locations&#x5B;0].country.city.name + &quot; - &quot; + .hostname + &quot;.conf&quot;),
      ip: .station,
      publicKey: (.technologies | .&#x5B;] | select(.identifier == &quot;wireguard_udp&quot;) | .metadata | .&#x5B;] | .value)
    } |
    {
      filename: .filename,
      config: &#x5B;
        &quot;# &quot; + .filename,
        &quot;&quot;,
        &quot;&#x5B;Interface]&quot;,
        &quot;PrivateKey = \($private_key)&quot;,
        &quot;Address = 10.5.0.2/32&quot;,
        &quot;DNS = \($dns)&quot;,
        &quot;&quot;,
        &quot;&#x5B;Peer]&quot;,
        &quot;PublicKey = &quot; + .publicKey,
        &quot;AllowedIPs = 0.0.0.0/0, ::/0&quot;,
        &quot;Endpoint = &quot; + .ip + &quot;:51820&quot;
      ] | join(&quot;\n&quot;)
    } |
    &quot;echo \&quot;&quot; + .config + &quot;\&quot; &gt; \&quot;&quot; + .filename + &quot;\&quot;&quot;
  &#039; | sh
</pre></div>


<p>Required Changes:</p>



<ul class="wp-block-list">
<li><strong>Line 3</strong>: Replace <strong>[YOUR-ACCESS-TOKEN]</strong> with the access token you have just copied.</li>
</ul>



<p>Optional Changes:</p>



<ul class="wp-block-list">
<li><strong>Line 4</strong>: By default, this script generates 3 different WireGuard config files based on your location. If one of the servers is oversaturated, you can point to a different server next time without rerunning the script.</li>



<li><strong>Line 5</strong>: Currently, I use CloudFlare DNS (1.1.1.1) since it has the fastest response time. However, you can update it to point to your favorite DNS server, for example, Google&#8217;s 8.8.8.8.</li>
</ul>



<p>Other Helpful Explanations:</p>



<ul class="wp-block-list">
<li><strong>Line 10</strong>: Retrieve your private key.</li>



<li><strong>Line 12</strong>: Retrieve the recommended WireGuard-compatible servers based on your current location and generate the WireGuard config files.</li>
</ul>



<p>Suppose you plan to travel to a different location with your travel router. In that case, typically, you want to pre-configure your travel router with the nearest WireGuard servers based on your destinations before departing. To do this, you can choose a desired location in the NordVPN software installed on your current machine before rerunning this script. For example, you might pick Finland because you fancy eating the delicious Kaalikääryleet that you can&#8217;t pronounce. Still, you want to do it safely before Instagramming it in real-time during your long weekend.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="284" height="827" src="https://myshittycode.com/wp-content/uploads/2024/06/5-nordvpn-destination-server.png?x45560" alt="" class="wp-image-2613" srcset="https://myshittycode.com/wp-content/uploads/2024/06/5-nordvpn-destination-server.png 284w, https://myshittycode.com/wp-content/uploads/2024/06/5-nordvpn-destination-server-103x300.png 103w" sizes="auto, (max-width: 284px) 100vw, 284px" /></figure>



<p>After running the script, you should see 3 WireGuard configuration files created.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; highlight: [4,5,6]; title: ; notranslate">
$ ls -a | cat                                                                                ✔ 
.
..
Finland - Helsinki - fi183.nordvpn.com.conf
Finland - Helsinki - fi195.nordvpn.com.conf
Finland - Helsinki - fi198.nordvpn.com.conf
nordvpn-wireguard.sh
</pre></div>


<h2 class="wp-block-heading" id="step-3-configure-wire-guard-on-router">Step 3: Configure WireGuard on Router</h2>



<p>The following instructions apply to the GL.iNet travel routers, in my case, Beryl AX (GL-MT3000). Follow your router&#8217;s instructions as needed.</p>



<p><strong>IMPORTANT:</strong> Before proceeding, ensure you have disabled the VPN from your machine so that it relies on the VPN configured on the travel router based on the steps below.</p>



<ul class="wp-block-list">
<li>Change your SSID to point to your travel router.</li>



<li>Go to <a href="http://192.168.8.1/">http://192.168.8.1/</a></li>



<li>Log into the Admin Panel.</li>



<li>Go to <strong>VPN</strong> > <strong>WireGuard Client</strong>.</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="553" src="https://myshittycode.com/wp-content/uploads/2024/06/6-router-wireguard-client-1024x553.png?x45560" alt="" class="wp-image-2625" srcset="https://myshittycode.com/wp-content/uploads/2024/06/6-router-wireguard-client-1024x553.png 1024w, https://myshittycode.com/wp-content/uploads/2024/06/6-router-wireguard-client-300x162.png 300w, https://myshittycode.com/wp-content/uploads/2024/06/6-router-wireguard-client-768x415.png 768w, https://myshittycode.com/wp-content/uploads/2024/06/6-router-wireguard-client.png 1254w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Upload the WireGuard configuration files. Rename the <strong>New Provider</strong> group to <strong>NordVPN</strong> to make it more meaningful.</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="553" src="https://myshittycode.com/wp-content/uploads/2024/06/7-router-wireguard-config-1024x553.png?x45560" alt="" class="wp-image-2626" srcset="https://myshittycode.com/wp-content/uploads/2024/06/7-router-wireguard-config-1024x553.png 1024w, https://myshittycode.com/wp-content/uploads/2024/06/7-router-wireguard-config-300x162.png 300w, https://myshittycode.com/wp-content/uploads/2024/06/7-router-wireguard-config-768x415.png 768w, https://myshittycode.com/wp-content/uploads/2024/06/7-router-wireguard-config.png 1249w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Pick a server and click <strong>Start</strong>.</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="650" height="345" src="https://myshittycode.com/wp-content/uploads/2024/06/8-router-start-server.png?x45560" alt="" class="wp-image-2627" srcset="https://myshittycode.com/wp-content/uploads/2024/06/8-router-start-server.png 650w, https://myshittycode.com/wp-content/uploads/2024/06/8-router-start-server-300x159.png 300w" sizes="auto, (max-width: 650px) 100vw, 650px" /></figure>



<ul class="wp-block-list">
<li>After a few seconds, the icon should change from orange to green.</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="647" height="340" src="https://myshittycode.com/wp-content/uploads/2024/06/9-router-successful-connection.png?x45560" alt="" class="wp-image-2628" srcset="https://myshittycode.com/wp-content/uploads/2024/06/9-router-successful-connection.png 647w, https://myshittycode.com/wp-content/uploads/2024/06/9-router-successful-connection-300x158.png 300w" sizes="auto, (max-width: 647px) 100vw, 647px" /></figure>



<ul class="wp-block-list">
<li>Go to <a href="https://whatismyipaddress.com/" target="_blank" rel="noopener">https://whatismyipaddress.com/</a> to verify your IP. The IP should point to your VPN server&#8217;s location.</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="626" src="https://myshittycode.com/wp-content/uploads/2024/06/10-whats-my-ip-1024x626.png?x45560" alt="" class="wp-image-2629" srcset="https://myshittycode.com/wp-content/uploads/2024/06/10-whats-my-ip-1024x626.png 1024w, https://myshittycode.com/wp-content/uploads/2024/06/10-whats-my-ip-300x183.png 300w, https://myshittycode.com/wp-content/uploads/2024/06/10-whats-my-ip-768x469.png 768w, https://myshittycode.com/wp-content/uploads/2024/06/10-whats-my-ip.png 1227w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Enjoy your <a href="https://www.google.com/search?sca_esv=b1ced915f33cbde0&amp;sca_upv=1&amp;q=Kaalik%C3%A4%C3%A4ryleet&amp;uds=ADvngMiIMiMH9LyyITANaU-tP7Tx_LoyDqWcuxLdAWjbiiPItTQIMJGqCilQ2P9bV1Dv6O-7T2R2WCCQCUAhxHSNZBXI7F-P9Lgqb8hx22E96rmdQ6wSH_7tq3REoY56wvh7NG60WLKZI4VCaaPBp1i0LfZE9RFaY_CmVZT2gnwKxtj0GgYDgVbx3eDESic00sPypgG1A0AVu4aWss3lmCsEJl7wi5kFTFiN1r0XgRykkdXUCaukfrxB5iO82Ulrno5Sy3CnaRDSnoeot-F_lu-Hbt21Rh6sTXTGTzkA3GbutH2O6ROk5Jv_DeyhhPz34u0R0kL3NOvaf1_plkXKARr8IzQdJR8YuA&amp;udm=2&amp;prmd=ivsnmbtz&amp;sa=X&amp;ved=2ahUKEwjmscz8ocyGAxUNJNAFHT8YGMYQtKgLegQIDBAB&amp;biw=1673&amp;bih=1399&amp;dpr=1" target="_blank" rel="noopener">Kaalikääryleet</a>!</li>
</ul>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2024/06/08/nordvpn-extracting-wireguard-configuration/">NordVPN: Extracting WireGuard Configuration</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2024/06/08/nordvpn-extracting-wireguard-configuration/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2604</post-id>	</item>
		<item>
		<title>Rclone: Backing Up Synology NAS to GCP</title>
		<link>https://myshittycode.com/2023/10/03/rclone-backing-up-synology-nas-to-gcp/</link>
					<comments>https://myshittycode.com/2023/10/03/rclone-backing-up-synology-nas-to-gcp/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 03 Oct 2023 14:29:13 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Google Cloud Platform]]></category>
		<category><![CDATA[Google Cloud Storage]]></category>
		<category><![CDATA[Rclone]]></category>
		<category><![CDATA[Synology NAS]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=2396</guid>

					<description><![CDATA[<p>This post shows how you can use Rclone to back up your data from a Synology NAS to a storage bucket in GCP. Why Backing Up Synology NAS Backing up data is like wearing a seat belt when driving, where nothing bad happens 99% of the time. However, when the 1% strikes unexpectedly one day, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2023/10/03/rclone-backing-up-synology-nas-to-gcp/">Rclone: Backing Up Synology NAS to GCP</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#why-backing-up-synology-nas">Why Backing Up Synology NAS</a></li><li><a href="#why-rclone">Why Rclone</a></li><li><a href="#why-gcp">Why GCP</a></li><li><a href="#configuration">Configuration</a><ul><li><a href="#setting-up-gcp-resources">Setting up GCP Resources</a></li><li><a href="#setting-up-rclone-in-synology-nas">Setting Up Rclone in Synology NAS</a><ul><li><a href="#ways-to-install-rclone">Ways to Install Rclone</a></li><li><a href="#whats-in-docker-appdata-rclone">What&#8217;s in /docker/appdata/rclone</a></li><li><a href="#downloading-docker-image">Downloading Docker Image</a></li><li><a href="#creating-docker-container-with-dry-run">Creating Docker Container (with &#8211;dry-run)</a></li><li><a href="#creating-docker-container-without-dry-run">Creating Docker Container (without &#8211;dry-run)</a></li><li><a href="#scheduling-docker-container-to-run">Scheduling Docker Container to Run</a></li></ul></li></ul></li></ul></nav></div>



<p>This post shows how you can use Rclone to back up your data from a Synology NAS to a storage bucket in GCP.</p>



<h2 class="wp-block-heading" id="why-backing-up-synology-nas">Why Backing Up Synology NAS</h2>



<p>Backing up data is like wearing a seat belt when driving, where nothing bad happens 99% of the time. However, when the 1% strikes unexpectedly one day, the &#8220;future&#8221; you will be grateful that you do not lose any precious data, such as childhood photos, important documents, etc. </p>



<p>When you own several machines at home, it makes sense to centralize the shared data in a local NAS, such as Synology NAS. You may also configure Time Machine to seamlessly back up each Mac to Synology NAS every weekend. It is equally important to back up the data in Synology NAS to the cloud. Your car&#8217;s seat belt might be faulty, but you still have an airbag. If a thief breaks into your house, steals your shiny NAS, and burns your house down, you still have your data in the cloud. </p>



<p>The moral of the story is always to back up your data, preferably using the <a href="https://www.cisa.gov/sites/default/files/publications/data_backup_options.pdf" target="_blank" rel="noopener">3-2-1 rule</a>.</p>



<h2 class="wp-block-heading" id="why-rclone">Why Rclone</h2>



<p>The most confusing part of the Synology NAS backup process is there are several ways to do this. The three popular solutions are <a href="https://www.synology.com/en-global/dsm/feature/cloud_sync" target="_blank" rel="noopener">Cloud Sync</a>, <a href="https://www.synology.com/en-global/dsm/feature/hyper_backup" target="_blank" rel="noopener">Hyper Backup</a>, and <a href="https://rclone.org/" target="_blank" rel="noopener">Rclone</a>. Each solution allows us to push data to various cloud providers. This <a href="https://www.reddit.com/r/synology/comments/hsy29y/hyper_backup_vs_cloud_sync_vs_rclone/" target="_blank" rel="noopener">Reddit post</a> nicely sums it all up. If I can summarize the most significant disadvantage of each solution in a few words, it will be:</p>



<ul class="wp-block-list">
<li>Cloud Sync silently ignores file names with unsupported characters.</li>



<li>Hyper Backup landlocks you to Synology solution because you can&#8217;t browse the backed-up files in the cloud.</li>



<li>Rclone doesn&#8217;t have a pretty GUI.</li>
</ul>



<p>Rclone seems more palatable among these solutions because I know all my data will be backed up. When disaster strikes next time, I also don&#8217;t have to deal with the proprietary format during my data recovery process. Who knows if Synology will still be around 20 years from now?</p>



<h2 class="wp-block-heading" id="why-gcp">Why GCP</h2>



<p>In the past, I configured my Synology NAS to perform a seamless backup to <a href="https://www.crashplan.com/en-us/" target="_blank" rel="noopener">CrashPlan</a> using <a href="https://hub.docker.com/r/jlesage/crashplan-pro" target="_blank" rel="noopener">this Docker solution</a>. It has worked flawlessly for many years. The main reasons I want to move the backups to my personal GCP org are:</p>



<ul class="wp-block-list">
<li>I have free GCP credits. Even without the GCP credits, based on <a href="https://cloud.google.com/products/calculator" target="_blank" rel="noopener">the GCP Pricing Calculator</a>, it is still cheaper to back up my data to a regional <a href="https://cloud.google.com/storage/docs/storage-classes#classes" target="_blank" rel="noopener">Archive storage</a> bucket than CrashPlan.</li>



<li>I can customize the number of backup versions and retention policies.</li>



<li>It is faster to recover all my data if needed.</li>



<li>I want to secure the data and GCP resources myself.</li>
</ul>



<p>You can swap out GCP with a cloud provider of your choice. For example, you can use Rclone to back up all your photos to <a href="https://www.amazon.com/b/?node=15547130011" target="_blank" rel="noopener">Amazon Photos</a> for free if you have a Prime membership and your <a href="https://www.amazon.com/gp/help/customer/display.html?nodeId=GGU2SU8Y22DZYRMQ" target="_blank" rel="noopener">photo formats are supported</a>. My RAW images (supported) also have corresponding XMP files (not supported), and I want to back up other file formats too.</p>



<h2 class="wp-block-heading" id="configuration">Configuration</h2>



<p>This diagram below helps you to visualize the solution.</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="514" src="https://myshittycode.com/wp-content/uploads/2023/08/synology-to-gcp-1-1024x514.png?x45560" alt="Synology NAS" class="wp-image-2418" srcset="https://myshittycode.com/wp-content/uploads/2023/08/synology-to-gcp-1-1024x514.png 1024w, https://myshittycode.com/wp-content/uploads/2023/08/synology-to-gcp-1-300x151.png 300w, https://myshittycode.com/wp-content/uploads/2023/08/synology-to-gcp-1-768x386.png 768w, https://myshittycode.com/wp-content/uploads/2023/08/synology-to-gcp-1.png 1312w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading" id="setting-up-gcp-resources">Setting up GCP Resources</h3>



<p>The best way to secure the data backups is to create a separate GCP project where only a specific service account has sufficient permission to write to a storage bucket. At a high level:</p>



<ul class="wp-block-list">
<li>Create a GCP project.</li>



<li>Create a storage bucket.
<ul class="wp-block-list">
<li>Enable object versioning and limit them to N versions (to prevent rising storage costs).</li>
</ul>
</li>



<li>Create a service account.</li>



<li>Grant service account with Storage Object Admin (roles/storage.objectAdmin) at the project level.</li>



<li>Create a service account key.</li>



<li>Download the service account key file in JSON format to the local machine first. In this post, this file is named <strong>service-account.json</strong>.</li>



<li><strong>BONUS</strong>: If you are paranoid, <a href="https://myshittycode.com/2023/08/18/vpc-sc-2-ways-to-fix-no_matching_access_level-error/" data-type="post" data-id="2359">configure a VPC Service Control perimeter and put that project within the perimeter</a>. This ensures only the whitelisted IPs can access these project resources. This way, even if the service account key is compromised, adversaries cannot access the protected resources unless they also spoof the IPs.</li>
</ul>



<h3 class="wp-block-heading" id="setting-up-rclone-in-synology-nas">Setting Up Rclone in Synology NAS</h3>



<h4 class="wp-block-heading" id="ways-to-install-rclone">Ways to Install Rclone</h4>



<p>There are multiple ways to install Rclone in Synology NAS:</p>



<ul class="wp-block-list">
<li><a href="https://rclone.org/install/" target="_blank" rel="noopener">Install Rclone</a> directly in Synology NAS.</li>



<li>Install Rclone using Docker (<a href="https://hub.docker.com/r/rclone/rclone" target="_blank" rel="noopener">rclone/rclone</a>).</li>



<li>Install Rclone with GUI using Docker (<a href="https://hub.docker.com/r/romancin/rclonebrowser" target="_blank" rel="noopener">romancin/rclonebrowser</a>).</li>
</ul>



<p>In this post, I use the second solution (without GUI) because simpler implementation means less chance of the tool breaking in the future. Besides, this is a &#8220;set-and-forget&#8221; process, and I don&#8217;t need to use the GUI most of the time.</p>



<h4 class="wp-block-heading" id="whats-in-docker-appdata-rclone">What&#8217;s in /docker/appdata/rclone</h4>



<p>/docker/appdata should already exist when the Docker package is installed in Synology NAS. You only need to create a child folder named <strong>rclone</strong> (or any name you like). This folder contains three files:</p>



<ul class="wp-block-list">
<li><strong>excludes.txt</strong> = File patterns to be excluded from the backup process.</li>



<li><strong>rclone.conf</strong> = Rclone configuration.</li>



<li><strong>service-account.json</strong> = The service account key file that you downloaded to your local machine from GCP.</li>
</ul>



<p>Here&#8217;s my example of <strong>excludes.txt</strong>, and customize it to your needs:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
@eaDir/**
.**
</pre></div>


<p><strong>rclone.conf</strong> can be generated using <strong>rclone config</strong> command. However, that must be done outside Synology NAS (i.e., on your local machine). That said, most of this command&#8217;s interactive steps are unnecessary since you created the storage bucket earlier. All you need is exactly this and nothing else:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&#x5B;gcp]
type = google cloud storage
service_account_file = /config/rclone/service-account.json
</pre></div>


<h4 class="wp-block-heading" id="downloading-docker-image">Downloading Docker Image</h4>



<p>Go to <strong>DSM</strong> &gt; <strong>Docker</strong> to download rclone/rclone image. </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="586" src="https://myshittycode.com/wp-content/uploads/2023/10/1-download-image-1024x586.png?x45560" alt="" class="wp-image-2504" srcset="https://myshittycode.com/wp-content/uploads/2023/10/1-download-image-1024x586.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/1-download-image-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/1-download-image-768x440.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/1-download-image-1536x880.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/1-download-image.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h4 class="wp-block-heading" id="creating-docker-container-with-dry-run">Creating Docker Container (with &#8211;dry-run)</h4>



<p>This step ensures the Rclone is configured properly before any files are copied to the storage bucket to prevent incurring unnecessary costs.</p>



<p>First, create a new container.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="584" src="https://myshittycode.com/wp-content/uploads/2023/10/2-container-create-1024x584.png?x45560" alt="" class="wp-image-2505" srcset="https://myshittycode.com/wp-content/uploads/2023/10/2-container-create-1024x584.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/2-container-create-300x171.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/2-container-create-768x438.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/2-container-create-1536x876.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/2-container-create.png 1968w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Use rclone/rclone image.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="588" src="https://myshittycode.com/wp-content/uploads/2023/10/3-container-image-1024x588.png?x45560" alt="" class="wp-image-2506" srcset="https://myshittycode.com/wp-content/uploads/2023/10/3-container-image-1024x588.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/3-container-image-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/3-container-image-768x441.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/3-container-image-1536x881.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/3-container-image.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>No changes to the network settings.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="589" src="https://myshittycode.com/wp-content/uploads/2023/10/4-container-network-1024x589.png?x45560" alt="" class="wp-image-2507" srcset="https://myshittycode.com/wp-content/uploads/2023/10/4-container-network-1024x589.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/4-container-network-300x173.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/4-container-network-768x442.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/4-container-network-1536x884.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/4-container-network.png 1968w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Enter the container name, and go to <strong>Advanced Settings</strong>.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="589" src="https://myshittycode.com/wp-content/uploads/2023/10/5-container-general-settings-1024x589.png?x45560" alt="" class="wp-image-2508" srcset="https://myshittycode.com/wp-content/uploads/2023/10/5-container-general-settings-1024x589.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/5-container-general-settings-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/5-container-general-settings-768x441.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/5-container-general-settings-1536x883.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/5-container-general-settings.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Under <strong>Execution Command</strong>, enter the following command:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sync /data gcp:&#x5B;BUCKET_NAME] --exclude-from /config/rclone/excludes.txt --gcs-bucket-policy-only --verbose --dry-run
</pre></div>


<p>Replace <strong>[BUCKET_NAME]</strong> with your own bucket name.</p>



<p><strong>IMPORTANT:</strong> Synology does not allow us to edit the execution command after creating a container!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="584" src="https://myshittycode.com/wp-content/uploads/2023/10/6-container-advanced-settings-1-1024x584.png?x45560" alt="" class="wp-image-2531" srcset="https://myshittycode.com/wp-content/uploads/2023/10/6-container-advanced-settings-1-1024x584.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/6-container-advanced-settings-1-300x171.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/6-container-advanced-settings-1-768x438.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/6-container-advanced-settings-1-1536x876.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/6-container-advanced-settings-1.png 1970w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>No changes to the port settings.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="588" src="https://myshittycode.com/wp-content/uploads/2023/10/7-container-port-settings-1024x588.png?x45560" alt="" class="wp-image-2510" srcset="https://myshittycode.com/wp-content/uploads/2023/10/7-container-port-settings-1024x588.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/7-container-port-settings-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/7-container-port-settings-768x441.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/7-container-port-settings-1536x882.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/7-container-port-settings.png 1964w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Define the volume mounts:</p>



<ul class="wp-block-list">
<li>/config/rclone = contains the Rclone configuration files.</li>



<li>/data = contains data to be backed up.
<ul class="wp-block-list">
<li>Because you can&#8217;t perform a volume mount on root /, each root folder needs to be volume-mounted to a subfolder within /data that you wish to back up.</li>
</ul>
</li>
</ul>



<p><strong>TIP:</strong> Consider mounting a data folder with the least amount of data when doing the dry run test. You can add/remove folders on an existing container later.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="587" src="https://myshittycode.com/wp-content/uploads/2023/10/8-container-volume-settings-1024x587.png?x45560" alt="" class="wp-image-2511" srcset="https://myshittycode.com/wp-content/uploads/2023/10/8-container-volume-settings-1024x587.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/8-container-volume-settings-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/8-container-volume-settings-768x440.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/8-container-volume-settings-1536x881.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/8-container-volume-settings.png 1964w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Review the summary.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="588" src="https://myshittycode.com/wp-content/uploads/2023/10/9-container-summary-1024x588.png?x45560" alt="" class="wp-image-2512" srcset="https://myshittycode.com/wp-content/uploads/2023/10/9-container-summary-1024x588.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/9-container-summary-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/9-container-summary-768x441.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/9-container-summary-1536x882.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/9-container-summary.png 1964w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Once the container is created, click on the toggle to run it.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="585" src="https://myshittycode.com/wp-content/uploads/2023/10/10-container-created-1024x585.png?x45560" alt="" class="wp-image-2513" srcset="https://myshittycode.com/wp-content/uploads/2023/10/10-container-created-1024x585.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/10-container-created-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/10-container-created-768x439.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/10-container-created-1536x878.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/10-container-created.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Review the container log. You can drop a few files into the mounted folder and rerun the container. The files should show up in the log.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="633" src="https://myshittycode.com/wp-content/uploads/2023/10/11-container-run-log-1024x633.png?x45560" alt="" class="wp-image-2514" srcset="https://myshittycode.com/wp-content/uploads/2023/10/11-container-run-log-1024x633.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/11-container-run-log-300x185.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/11-container-run-log-768x475.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/11-container-run-log-1536x949.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/11-container-run-log.png 1854w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h4 class="wp-block-heading" id="creating-docker-container-without-dry-run">Creating Docker Container (without &#8211;dry-run)</h4>



<p>Now that you have a working container to perform the dry run test, it&#8217;s time to back up the data to the cloud.</p>



<p>As mentioned earlier, it is not possible to edit the existing container&#8217;s execution command. The existing container contains the <strong>&#8211;dry-run</strong> flag on the execution command. The simplest way is to export the container setting, which will be used to create a new container without the <strong>&#8211;dry-run</strong> flag.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="585" src="https://myshittycode.com/wp-content/uploads/2023/10/12-container-export-1024x585.png?x45560" alt="" class="wp-image-2515" srcset="https://myshittycode.com/wp-content/uploads/2023/10/12-container-export-1024x585.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/12-container-export-300x171.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/12-container-export-768x439.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/12-container-export-1536x877.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/12-container-export.png 1972w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Export just the container settings to a local machine.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="585" src="https://myshittycode.com/wp-content/uploads/2023/10/13-container-export-local-1024x585.png?x45560" alt="" class="wp-image-2516" srcset="https://myshittycode.com/wp-content/uploads/2023/10/13-container-export-local-1024x585.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/13-container-export-local-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/13-container-export-local-768x439.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/13-container-export-local-1536x878.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/13-container-export-local.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Open the JSON file, locate and remove <strong>&#8211;dry-run</strong> from <strong>cmd</strong>. Save the file.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; highlight: [4]; title: ; notranslate">
{
   &quot;CapAdd&quot; : &#x5B;],
   &quot;CapDrop&quot; : &#x5B;],
   &quot;cmd&quot; : &quot;sync /data gcp:&#x5B;BUCKET_NAME] --exclude-from /config/rclone/excludes.txt --gcs-bucket-policy-only --verbose --dry-run&quot;,
   &quot;cpu_priority&quot; : 0,
   &quot;enable_publish_all_ports&quot; : false,
   ...
}
</pre></div>


<p>Return to the Docker container window to import this JSON file to create a new container.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="582" src="https://myshittycode.com/wp-content/uploads/2023/10/14-container-import-1024x582.png?x45560" alt="" class="wp-image-2517" srcset="https://myshittycode.com/wp-content/uploads/2023/10/14-container-import-1024x582.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/14-container-import-300x171.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/14-container-import-768x437.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/14-container-import-1536x873.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/14-container-import.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Upload the modified JSON file and provide a new container name.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="586" src="https://myshittycode.com/wp-content/uploads/2023/10/15-container-import-local-1024x586.png?x45560" alt="" class="wp-image-2518" srcset="https://myshittycode.com/wp-content/uploads/2023/10/15-container-import-local-1024x586.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/15-container-import-local-300x172.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/15-container-import-local-768x440.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/15-container-import-local-1536x879.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/15-container-import-local.png 1964w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Now, there are 2 Rclone containers: one with the <strong>&#8211;dry-run</strong> flag and another without it. It is up to you whether to retain or delete the container with the <strong>&#8211;dry-run</strong> flag. </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="584" src="https://myshittycode.com/wp-content/uploads/2023/10/16-container-import-successful-1024x584.png?x45560" alt="" class="wp-image-2519" srcset="https://myshittycode.com/wp-content/uploads/2023/10/16-container-import-successful-1024x584.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/16-container-import-successful-300x171.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/16-container-import-successful-768x438.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/16-container-import-successful-1536x876.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/16-container-import-successful.png 1964w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h4 class="wp-block-heading" id="scheduling-docker-container-to-run">Scheduling Docker Container to Run</h4>



<p>To ensure the Rclone runs to back up the files to the cloud, create a task scheduler. In this example, a triggered task is created so that Rclone can perform the backups on boot-up.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="575" src="https://myshittycode.com/wp-content/uploads/2023/10/17-scheduler-create-1024x575.png?x45560" alt="" class="wp-image-2520" srcset="https://myshittycode.com/wp-content/uploads/2023/10/17-scheduler-create-1024x575.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/17-scheduler-create-300x168.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/17-scheduler-create-768x431.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/17-scheduler-create-1536x862.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/17-scheduler-create.png 2024w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Ensure to run the task as root.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="574" src="https://myshittycode.com/wp-content/uploads/2023/10/18-scheduler-general-1024x574.png?x45560" alt="" class="wp-image-2521" srcset="https://myshittycode.com/wp-content/uploads/2023/10/18-scheduler-general-1024x574.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/18-scheduler-general-300x168.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/18-scheduler-general-768x430.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/18-scheduler-general-1536x860.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/18-scheduler-general.png 2028w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Specify the following script to execute. This script ensures the Docker service is running first before starting the container to perform the backup.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
while (synopkg status Docker | jq -r &#039;.status&#039; | grep -vq &quot;running&quot;); do
  sleep 10
done

docker container start rclone
</pre></div>


<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="575" src="https://myshittycode.com/wp-content/uploads/2023/10/19-scheduler-task-settings-1024x575.png?x45560" alt="" class="wp-image-2522" srcset="https://myshittycode.com/wp-content/uploads/2023/10/19-scheduler-task-settings-1024x575.png 1024w, https://myshittycode.com/wp-content/uploads/2023/10/19-scheduler-task-settings-300x168.png 300w, https://myshittycode.com/wp-content/uploads/2023/10/19-scheduler-task-settings-768x431.png 768w, https://myshittycode.com/wp-content/uploads/2023/10/19-scheduler-task-settings-1536x862.png 1536w, https://myshittycode.com/wp-content/uploads/2023/10/19-scheduler-task-settings.png 2028w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>That&#8217;s it! Every time the Synology NAS boots up, the Rclone container will run to perform any necessary data backup to the cloud.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2023/10/03/rclone-backing-up-synology-nas-to-gcp/">Rclone: Backing Up Synology NAS to GCP</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2023/10/03/rclone-backing-up-synology-nas-to-gcp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2396</post-id>	</item>
		<item>
		<title>WordPress: Creating Gutenberg-Block Compatible Posts Using Rest API</title>
		<link>https://myshittycode.com/2023/01/03/wordpress-creating-gutenberg-block-compatible-posts-using-rest-api/</link>
					<comments>https://myshittycode.com/2023/01/03/wordpress-creating-gutenberg-block-compatible-posts-using-rest-api/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 03 Jan 2023 17:27:35 +0000</pubDate>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Gutenberg]]></category>
		<category><![CDATA[Rest]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=1988</guid>

					<description><![CDATA[<p>This article shows how you can dynamically create new WordPress posts using REST API that is compatible with Gutenberg blocks. When done correctly, there is no need to manually convert the content from Classic Editor to Gutenberg Block Editor, or fix incorrectly converted blocks. This is a big time saver when you plan to create [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2023/01/03/wordpress-creating-gutenberg-block-compatible-posts-using-rest-api/">WordPress: Creating Gutenberg-Block Compatible Posts Using Rest API</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This article shows how you can dynamically create new WordPress posts using REST API that is compatible with Gutenberg blocks. When done correctly, there is no need to manually convert the content from Classic Editor to Gutenberg Block Editor, or fix incorrectly converted blocks. This is a big time saver when you plan to create many posts using REST API.</p>



<p>This article also assumes you know how to dynamically <a href="https://developer.wordpress.org/rest-api/reference/posts/#create-a-post" target="_blank" rel="noopener">create a WordPress post using REST API</a>.</p>



<p>For simplicity, the cURL command is used instead of a programming language like PHP or Python.</p>



<h2 class="wp-block-heading" id="problem">PROBLEM</h2>



<p>Let&#8217;s assume we want to create a post with one paragraph and 2 columns, each containing a paragraph too. When creating a similar structure directly using Gutenberg Block Editor, the generated source code like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;p&gt;hello&lt;/p&gt;
&lt;div class=&quot;is-layout-flex wp-block-columns&quot;&gt;
&lt;div class=&quot;is-layout-flow wp-block-column&quot;&gt;
&lt;p&gt;left&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;is-layout-flow wp-block-column&quot;&gt;
&lt;p&gt;right&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</pre></div>


<p>Using the same structure, we are going to create the same post using REST API instead:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
export auth=...
export wp_url=...

content=$(echo &#039;
&lt;p&gt;hello&lt;/p&gt;
&lt;div class=&quot;is-layout-flex wp-block-columns&quot;&gt;
&lt;div class=&quot;is-layout-flow wp-block-column&quot;&gt;
&lt;p&gt;left&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;is-layout-flow wp-block-column&quot;&gt;
&lt;p&gt;right&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&#039; | jq -Rsa .)

curl -H &quot;Content-Type: application/json&quot; \
  -H &quot;Authorization: Basic $auth&quot; \
  -X POST &quot;$wp_url/wp-json/wp/v2/posts&quot; \
  -d &quot;{\&quot;title\&quot;:\&quot;test\&quot;, \&quot;content\&quot;: $content}&quot;

</pre></div>


<p>When opening the newly created post in edit mode, the post uses Classic Editor, and not Gutenberg Block Editor. </p>



<figure class="wp-block-image aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_22_49_AM-1024x445.png?x45560" alt="" class="wp-image-1991" width="768" height="334" srcset="https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_22_49_AM-1024x445.png 1024w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_22_49_AM-300x130.png 300w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_22_49_AM-768x334.png 768w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_22_49_AM.png 1352w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>When attempting to convert the post to Gutenberg blocks&#8230;</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_23_02_AM-1024x362.png?x45560" alt="" class="wp-image-1992" width="768" height="272" srcset="https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_23_02_AM-1024x362.png 1024w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_23_02_AM-300x106.png 300w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_23_02_AM-768x271.png 768w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_23_02_AM.png 1348w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>Some blocks are converted successfully. However, most of the complex or nested blocks are converted to Custom HTML blocks instead. This is because it is not smart enough to know which Gutenberg blocks to use.</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.23.16-AM-1024x604.png?x45560" alt="" class="wp-image-1993" width="768" height="453" srcset="https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.23.16-AM-1024x604.png 1024w, https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.23.16-AM-300x177.png 300w, https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.23.16-AM-768x453.png 768w, https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.23.16-AM.png 1336w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>This becomes problematic and time-consuming when you have to manually convert each post to use Gutenberg Block Editor, and fix sections that failed to convert to the correct blocks.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="solution">SOLUTION</h2>



<p>If you know you are going to create future new posts using known Gutenberg blocks (ex: paragraph, column, image, etc), the easiest approach is to manually create a temporary post using Gutenberg Block Editor first.</p>



<p>Using the same example, the paragraph and 2-column structure are manually created using Gutenberg Block Editor.</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.26.09-AM-1024x359.png?x45560" alt="" class="wp-image-1994" width="768" height="269" srcset="https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.26.09-AM-1024x359.png 1024w, https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.26.09-AM-300x105.png 300w, https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.26.09-AM-768x270.png 768w, https://myshittycode.com/wp-content/uploads/2023/01/Screen-Shot-2023-01-03-at-10.26.09-AM.png 1362w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>Now, click on the kebab on the top right, then select <strong>Code editor</strong>.</p>



<figure class="wp-block-image aligncenter size-full is-resized"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_26_28_AM.png?x45560" alt="" class="wp-image-1995" width="468" height="746" srcset="https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_26_28_AM.png 624w, https://myshittycode.com/wp-content/uploads/2023/01/Screen_Shot_2023-01-03_at_10_26_28_AM-188x300.png 188w" sizes="auto, (max-width: 468px) 100vw, 468px" /></figure>



<p>This will display the source code in block format, which looks like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;hello&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:columns --&gt;
&lt;div class=&quot;wp-block-columns&quot;&gt;&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;!-- wp:paragraph --&gt;
&lt;p&gt;left&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;

&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;!-- wp:paragraph --&gt;
&lt;p&gt;right&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;&lt;/div&gt;
&lt;!-- /wp:columns --&gt;
</pre></div>


<p>Now that we know what the format looks like, we can automate the post creations using REST API.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
content=$(echo &#039;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;hello&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:columns --&gt;
&lt;div class=&quot;wp-block-columns&quot;&gt;&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;!-- wp:paragraph --&gt;
&lt;p&gt;left&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;

&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;!-- wp:paragraph --&gt;
&lt;p&gt;right&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;&lt;/div&gt;
&lt;!-- /wp:columns --&gt;
&#039; | jq -Rsa .)


curl -H &quot;Content-Type: application/json&quot; \
  -H &quot;Authorization: Basic $auth&quot; \
  -X POST &quot;$wp_url/wp-json/wp/v2/posts&quot; \
  -d &quot;{\&quot;title\&quot;:\&quot;test\&quot;, \&quot;content\&quot;: $content}&quot;
</pre></div>


<p>Finally, we can create methods/functions with our favorite programming language to generate these blocks, which will be fed to the REST API to create a new WordPress post that is 100% compatible with Gutenberg blocks. </p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2023/01/03/wordpress-creating-gutenberg-block-compatible-posts-using-rest-api/">WordPress: Creating Gutenberg-Block Compatible Posts Using Rest API</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2023/01/03/wordpress-creating-gutenberg-block-compatible-posts-using-rest-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1988</post-id>	</item>
		<item>
		<title>Squid: Configuring Whitelisted URLs</title>
		<link>https://myshittycode.com/2021/04/21/squid-configuring-whitelisted-urls/</link>
					<comments>https://myshittycode.com/2021/04/21/squid-configuring-whitelisted-urls/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 22 Apr 2021 03:01:40 +0000</pubDate>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Squid]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=1201</guid>

					<description><![CDATA[<p>PROBLEM To configure a proxy server that only allows whitelisted URLs through. SOLUTION Install Squid&#8230; in this case, on Ubuntu. Ensure the service is running. Create a file ( /etc/squid/whitelist.txt ) containing the whitelisted URLs. In this example, only one URL is whitelisted. To simplify the configuration, backup /etc/squid/squid.conf and create the same file with [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2021/04/21/squid-configuring-whitelisted-urls/">Squid: Configuring Whitelisted URLs</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>To configure a proxy server that only allows whitelisted URLs through.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>Install Squid&#8230; in this case, on Ubuntu.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt install -y squid
</pre></div>


<p>Ensure the service is running.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
my@shittycode:/etc/squid$ sudo systemctl status squid
● squid.service - Squid Web Proxy Server
Loaded: loaded (/lib/systemd/system/squid.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-04-21 17:20:54 CDT; 3min 3s ago
Docs: man:squid(8)
Process: 9008 ExecStartPre=/usr/sbin/squid --foreground -z (code=exited, status=0/SUCCESS)
Process: 9012 ExecStart=/usr/sbin/squid -sYC (code=exited, status=0/SUCCESS)
Main PID: 9013 (squid)
Tasks: 4 (limit: 44379)
Memory: 16.1M
CGroup: /system.slice/squid.service
├─9013 /usr/sbin/squid -sYC
├─9015 (squid-1) --kid squid-1 -sYC
├─9016 (logfile-daemon) /var/log/squid/access.log
└─9017 (pinger)

Apr 21 17:20:54 shittycode squid&#x5B;9015]: Max Swap size: 0 KB
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Using Least Load store dir selection
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Set Current Directory to /var/spool/squid
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Finished loading MIME types and icons.
Apr 21 17:20:54 shittycode squid&#x5B;9015]: HTCP Disabled.
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Pinger socket opened on FD 14
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Squid plugin modules loaded: 0
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Adaptation support is off.
Apr 21 17:20:54 shittycode squid&#x5B;9015]: Accepting HTTP Socket connections at local=&#x5B;::]:3128 remote=&#x5B;::] FD 12 flags=9
Apr 21 17:20:55 shittycode squid&#x5B;9015]: storeLateRelease: released 0 objects
</pre></div>


<p>Create a file ( <code>/etc/squid/whitelist.txt</code> ) containing the whitelisted URLs. In this example, only one URL is whitelisted.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
my@shittycode:/etc/squid$ cat whitelist.txt
www.google.com
</pre></div>


<p>To simplify the configuration, backup <code>/etc/squid/squid.conf</code> and create the same file with these minimal configurations.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
my@shittycode:/etc/squid$ cat squid.conf

# An ACL named &#039;whitelist&#039;
acl whitelist dstdomain &#039;/etc/squid/whitelist.txt&#039;

# Allow whitelisted URLs through
http_access allow whitelist

# Block the rest
http_access deny all

# Default port
http_port 3128
</pre></div>


<p>Restart the service to pick up the change.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo systemctl restart squid
</pre></div>


<p>To test the configuration, when hitting a non-whitelisted URL, it should return 403.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
my@shittycode:/etc/squid$ curl -x localhost:3128 -I -L yahoo.com
HTTP/1.1 403 Forbidden
Server: squid/4.10
Mime-Version: 1.0
Date: Wed, 21 Apr 2021 22:22:02 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3507
X-Squid-Error: ERR_ACCESS_DENIED 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from shittycode
X-Cache-Lookup: NONE from shittycode:3128
Via: 1.1 shittycode (squid/4.10)
Connection: keep-alive
</pre></div>


<p>When hitting a whitelisted URL, it should return 200.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
my@shittycode:/etc/squid$ curl -x localhost:3128 -I -L www.google.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP=&quot;This is not a P3P policy! See g.co/p3phelp for more info.&quot;
Date: Wed, 21 Apr 2021 22:21:03 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Expires: Wed, 21 Apr 2021 22:21:03 GMT
Cache-Control: private
Set-Cookie: 1P_JAR=2021-04-21-22; expires=Fri, 21-May-2021 22:21:03 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=214=AAK1Z6cV4cXlOGLIdHrKhiyzW2iBKpkN5-3OXvVrxEGrw-VekbvM1uFMMUAGubhAciT8NcyCVto2fpDPHJXRBECcqJRFTsUDNb3WBUNIgvK0zWpyxz8bl1aSqB22nQhf2fEwfDM9nAkVZyQG8rst054qOfAHO9kDvkrZRWn9HyM; expires=Thu, 21-Oct-2021 22:21:03 GMT; path=/; domain=.google.com; HttpOnly
X-Cache: MISS from shittycode
X-Cache-Lookup: MISS from shittycode:3128
Via: 1.1 shittycode (squid/4.10)
Connection: keep-alive
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2021/04/21/squid-configuring-whitelisted-urls/">Squid: Configuring Whitelisted URLs</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2021/04/21/squid-configuring-whitelisted-urls/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1201</post-id>	</item>
		<item>
		<title>Nginx: Requesting and Configuring SSL Certificate</title>
		<link>https://myshittycode.com/2020/06/25/nginx-requesting-and-configuring-ssl-certificate/</link>
					<comments>https://myshittycode.com/2020/06/25/nginx-requesting-and-configuring-ssl-certificate/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 25 Jun 2020 20:34:34 +0000</pubDate>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=1173</guid>

					<description><![CDATA[<p>INTRO Step by step instructions for my future self to obtain the SSL certificate and to configure it in Nginx because my fragile little brain cannot retain them at the moment. INSTRUCTIONS Generate a private key and store it in a safe place. Generate a certificate signing request (CSR). Request a SSL certificate from Certificate [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2020/06/25/nginx-requesting-and-configuring-ssl-certificate/">Nginx: Requesting and Configuring SSL Certificate</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">INTRO</h2>



<p>Step by step instructions for my future self to obtain the SSL certificate and to configure it in Nginx because my fragile little brain cannot retain them at the moment.</p>



<h2 class="wp-block-heading">INSTRUCTIONS</h2>



<p>Generate a private key and store it in a safe place.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
openssl genrsa -out myshittycode_com.key 2048

</pre></div>


<p>Generate a certificate signing request (CSR).</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
openssl req -new -sha256 \
  -key myshittycode_com.key \
  -out myshittycode_com.csr	\
  -subj &quot;/C=US/ST=ShittyState/L=ShittyCity/OU=ShittyUnit/O=ShittyCompany/CN=myshittycode.com&quot;

</pre></div>


<p>Request a SSL certificate from Certificate Authority (ex: Sectigo) using the generated CSR.</p>



<p>If approved, you will receive an email similar to the below.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="2008" height="1308" src="https://myshittycode.com/wp-content/uploads/2020/06/ssl-certificate-1.png?x45560" alt="ssl-certificate" class="wp-image-1175" srcset="https://myshittycode.com/wp-content/uploads/2020/06/ssl-certificate-1.png 2008w, https://myshittycode.com/wp-content/uploads/2020/06/ssl-certificate-1-300x195.png 300w, https://myshittycode.com/wp-content/uploads/2020/06/ssl-certificate-1-1024x667.png 1024w, https://myshittycode.com/wp-content/uploads/2020/06/ssl-certificate-1-768x500.png 768w, https://myshittycode.com/wp-content/uploads/2020/06/ssl-certificate-1-1536x1001.png 1536w" sizes="auto, (max-width: 2008px) 100vw, 2008px" /></figure>



<p>To configure the SSL certificate in Nginx, don&#8217;t use <b>Certificate (w/ chain), PEM encoded</b> because it contains the certificates in the following order:-</p>



<ul class="wp-block-list">
<li>Root CA certificate</li>



<li>Intermediate CA certificate</li>



<li>Certificate</li>
</ul>



<p>Nginx wants them in this order:-</p>



<ul class="wp-block-list">
<li>Certificate</li>



<li>Root CA certificate</li>



<li>Intermediate CA certificate</li>
</ul>



<p>To pull this off, download <b>Certificate only, PEM encoded</b> and <b>Root/Intermediate(s) only, PEM encoded</b>.</p>



<p>Then combine them into one file in the proper order.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
cat myshittycode_com_cert.cer myshittycode_com_interm.cer &gt; myshittycode_com_bundle.crt

</pre></div>


<p>In nginx.conf, add the bundle certificate, private key and server name.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; highlight: [4,5,6]; title: ; notranslate">
server {
  listen               443;
  ssl                  on;
  ssl_certificate      /etc/pki/tls/certs/myshittycode_com_bundle.crt;
  ssl_certificate_key  /etc/pki/tls/private/myshittycode_com.key;
  server_name          myshittycode.com;

  location / {
    ...
  }
}

</pre></div>


<p>Restart Nginx service.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2020/06/25/nginx-requesting-and-configuring-ssl-certificate/">Nginx: Requesting and Configuring SSL Certificate</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2020/06/25/nginx-requesting-and-configuring-ssl-certificate/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1173</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-18 08:42:34 by W3 Total Cache
-->