{"id":27,"date":"2022-05-02T21:37:43","date_gmt":"2022-05-02T21:37:43","guid":{"rendered":"https:\/\/nuclearwaffle.com\/?p=27"},"modified":"2022-05-03T00:47:27","modified_gmt":"2022-05-03T00:47:27","slug":"how-to-get-opnsense-and-self-signed-certs-working-with-nginx","status":"publish","type":"post","link":"https:\/\/www.nuclearwaffle.com\/?p=27","title":{"rendered":"How to get OPNsense and self-signed certs working with nginx"},"content":{"rendered":"\n<p>Right, so your configuration might look like this:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You have a site you&#8217;ve built up haphazardly and it&#8217;s got invalid or self-signed certificates.<\/li><li>You have OPNsense and nginx, running together.<\/li><li>You&#8217;ve followed <a href=\"https:\/\/forum.opnsense.org\/index.php?topic=19305.0\">this guide<\/a> to the letter and now you&#8217;re getting 502 errors because you also managed to put port forwards to the nginx client, which the guide didn&#8217;t tell you to do.<\/li><\/ol>\n\n\n\n<p>So what&#8217;s up?<br>Well, in short, probably nginx is barfing because it doesn&#8217;t like this part of the transaction:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The browser requests www.yoursite.com<\/li><li>Nginx takes that request and slaps your TLS certificate on it, branding it as Good To Go. Browser&#8217;s happy.<\/li><li>Nginx goes off to the Upstream Server and IMMEDIATELY DIES because it doesn&#8217;t like the invalid or self-signed certificates. It <em>could<\/em> handle the TLS connection, encrypting everything, but it barfs on the cert.<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>So what do you do? Well, you can either:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Make the Upstream link HTTP only. This gets around the problem, but it does mean you expose the pageviews, the password, all that, to anything that can see the traffic locally. Which may be more than you want.<\/li><li>Somehow get the TLS certificate into OPNsense so you can pick that cert. I didn&#8217;t figure out how to do that.<\/li><li>Turn off TLS cert verification, so nginx just accepts the cert it&#8217;s given. This is the one I did.<\/li><\/ol>\n\n\n\n<p>Some caveats:<\/p>\n\n\n\n<p>You had better only do this if you&#8217;re damned certain you own that server and it&#8217;s on your local network. No funny business having it elsewhere or out of your constant control; if anybody sticks a different server at that same IP, it&#8217;ll get accepted, and then it&#8217;ll look like the real site. YOU HAVE TO BE CAREFUL HERE. If you don&#8217;t know what you&#8217;re changing and why, you can get <em>really<\/em> screwed here.<\/p>\n\n\n\n<p>What&#8217;s this doing? Well, nginx is handing the TLS cert to the browser, so it&#8217;s happy, but then when it connects to the actual WordPress server or what have you, it gets a cert it then wants to verify is good. If it&#8217;s invalid, dead, expired, or self-signed, that can&#8217;t happen since there&#8217;s no Certificate Authority that issued it that nginx recognizes, so it fails. Unless you turn off verification, that is. If you do, it looks at the invalid cert and goes &#8220;eyeah, that&#8217;s fine I guess&#8221; and sets up the encrypted session without bothering to check. Kind of like when your sister smiles sweetly and flashes a fake ID at the club, and the bouncer figures she&#8217;s in that butter zone between 18 and 21 and lets her in because she&#8217;s cute and might like bouncers.<\/p>\n\n\n\n<p>She doesn&#8217;t, but she likes that bouncers think she does. And so it&#8217;s the same with your WordPress server.<\/p>\n\n\n\n<p>So how is this accomplished?<br>1. Go here:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"509\" height=\"162\" src=\"https:\/\/nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image.png\" alt=\"\" class=\"wp-image-28\" srcset=\"https:\/\/www.nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image.png 509w, https:\/\/www.nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image-300x95.png 300w\" sizes=\"auto, (max-width: 509px) 100vw, 509px\" \/><\/figure>\n\n\n\n<p>2. Edit your entry, and click Advanced.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"57\" src=\"https:\/\/nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image-1.png\" alt=\"\" class=\"wp-image-29\"\/><\/figure>\n\n\n\n<p>3. Turn this off, TAKING HEED OF THE VERY DIRE WARNING:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"77\" src=\"https:\/\/nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image-2.png\" alt=\"\" class=\"wp-image-30\" srcset=\"https:\/\/www.nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image-2.png 542w, https:\/\/www.nuclearwaffle.com\/wp-content\/uploads\/2022\/05\/image-2-300x43.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<p>4. Test your site again. If it works, it was a TLS problem, and was due to nginx not liking the certificate.<\/p>\n\n\n\n<p>Now if you&#8217;re very smart you get that cert put into OPNsense so nginx can look for it, and barf again if there&#8217;s a problem with it. This is the safe option. If you&#8217;re lazy and you are running a beater WordPress instance to write shit down for the inevitable configuration explosion where you have to redo half of half of the stuff you actually gave a shit about? Well, then you leave it as is, and fuckin&#8217; send it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Right, so your configuration might look like this: You have a site you&#8217;ve built up haphazardly and it&#8217;s got invalid or self-signed certificates. You have OPNsense and nginx, running together. You&#8217;ve followed this guide to the letter and now you&#8217;re getting 502 errors because you also managed to put port forwards to the nginx client,&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":7,"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nuclearwaffle.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}