title: WSL2 Nginx - Works on localhost but throws 403 Forbidden on 127.0.0.1 or custom host name
body: <p>I've been trying to setup nginx on my WSL2 running Ubuntu 20.04. I got pretty much the entire site setup. It's working when I visit http://localhost. But I want it to be on <a href="http://app.test" rel="nofollow noreferrer">http://app.test</a>. So I added it to the host and tried, it throws 403 Forbidden error. I've not changed anything in <code>nginx.conf</code>. This is what I have so far:</p>
  <p><strong>Server Block</strong></p>
  <pre><code>server {
          listen 80 default_server;
          listen [::]:80 default_server;
  
          root /var/www/html/app.test;
  
          # Add index.php to the list if you are using PHP
          index index.php index.html index.htm index.nginx-debian.html;
  
          server_name _;
  
          location / {
                  # First attempt to serve request as file, then
                  # as directory, then fall back to displaying a 404.
                  try_files $uri $uri/ =404;
          }
  }
  </code></pre>
  <p><strong>Permissions</strong></p>
  <p>The <code>/var/www/html/app.test</code> folder belongs to <code>www-data:www-data</code> user and group.</p>
  <p><strong>Hosts</strong></p>
  <p>I've added the following in both my Windows Hosts and on Ubuntu Hosts</p>
  <pre><code>127.0.0.1 app.test
  </code></pre>
  <p><strong>Findings</strong></p>
  <ol>
  <li>I checked the access.log. I've included 2 of the logs below. The first one is a non-working one (when visiting app.test) and the other is a working one (when visiting localhost).</li>
  </ol>
  <pre><code>127.0.0.1 - - [05/Nov/2020:00:07:09 +0400] &quot;GET / HTTP/1.0&quot; 403 564 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0;...&quot;
  
  ::1 - - [05/Nov/2020:00:01:13 +0400] &quot;GET / HTTP/1.1&quot; 304 0 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0;...
  </code></pre>
  <ol start="2">
  <li>I tried running a curl command from Windows Terminal, I get 200 OK for <code>http://localhost</code> but 403 Forbidden for <code>http://127.0.0.1</code></li>
  </ol>
  <p>Thanks!</p>