<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dika Mahendra</title>
    <description>The latest articles on DEV Community by Dika Mahendra (@dkmhndr).</description>
    <link>https://dev.to/dkmhndr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1398106%2F8eab9a62-6f4b-40be-a219-1de84f003e0e.png</url>
      <title>DEV Community: Dika Mahendra</title>
      <link>https://dev.to/dkmhndr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dkmhndr"/>
    <language>en</language>
    <item>
      <title>How to Reverse Proxy NextJS with NGINX</title>
      <dc:creator>Dika Mahendra</dc:creator>
      <pubDate>Sat, 30 Mar 2024 23:02:21 +0000</pubDate>
      <link>https://dev.to/dkmhndr/how-to-reverse-proxy-nextjs-with-nginx-1bh7</link>
      <guid>https://dev.to/dkmhndr/how-to-reverse-proxy-nextjs-with-nginx-1bh7</guid>
      <description>&lt;p&gt;Sup, let's get straight. Here's a simple tips to run your NextJS Pages (especially in dev environment, but also works on production ofc.) through Nginx. Before we started, I expect we're already have an Nginx configuration set up. &lt;/p&gt;

&lt;p&gt;Then, we're just simply adds these configs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Proxy NextJS Chunks, exception and websocket for HMR
location ~ ^/_?_next.* {
        proxy_pass [YOUR_NEXTJS_HOST_HERE];
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Yeah. But why?&lt;/strong&gt;&lt;br&gt;
My case might be rare. I wanted to partially merge my NextJS Page into my existing website with different tech stacks (don't ask me why I didn't use NextJS at first start 🥲). So instead of embedding my NextJS page that dependent to my existing my website which takes lot of time to load, those /_next routes which loads JS chunks and another NextJS optimized stuffs could be passed directly into node server so it can reduce the latency. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But, it's just not about latency.&lt;/strong&gt; &lt;br&gt;
Previously, to debug my NextJS pages that merged, i have to compile every;single;changes; into production build to make it works. It's makes me frustrated because it's also waste my time since the hot reload and &lt;em&gt;Webpack&lt;/em&gt; stuffs doesn't work due to 404 error etc. So, I tried to adds some reverse proxy to my config and that's it! Works like a charm.&lt;/p&gt;

&lt;p&gt;If you have the same cases, hope it helps.&lt;/p&gt;

&lt;p&gt;PS:&lt;br&gt;
I would also thanks to Farid Inawan (psps.. Check his cool Instagram account &lt;a href="https://www.instagram.com/frd.tech/"&gt;here!&lt;/a&gt; He's making content about tech stuffs too) who helped me simplify the configuration. :)&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>nginx</category>
    </item>
  </channel>
</rss>
