title: How to fix, "Error: Request failed with status code 404" in axios Next js
body: <blockquote>
    <p>I am using next js when trying to call an API endpoint(dispatching a
    redux action)in getInitialProps. I am getting the 404 error, my /api/
    is proxied in nginx server, all other routes work very well only this
    route is causing the problem.</p>
    
    <p>I have tried by changing the api fetch function call to async but
    still the same error.</p>
  </blockquote>
  
  <pre><code>static async getInitialProps({ store, query: { id } }) {
      await store.dispatch(fetchP(id));
      console.log('GetIntial');
      return { id };
   }
  </code></pre>
  
  <blockquote>
    <p>My action creator</p>
  </blockquote>
  
  <pre><code>export const fetchp = id =&gt; async dispatch =&gt; {
    dispatch({ type: FETCH_P_DETAILS_STARTED });
    await API.get(`ps/${id}`)
      .then(res =&gt; {
        console.log(res);
        dispatch({
          type: FETCH_P_DETAILS_SUCCESS,
          payload: res.data.data,
        });
      })
      .catch(err =&gt; {
        console.log(err);
        if (!err.response) {
          // network error
          err.message = 'Error: Network Error';
          console.log(err.message);
        } else if (err.code === 'ECONNABORTED') {
          console.log('Timeout');
        } else {
          err.message = err.message;
        }
        dispatch({
          type: FETCH_P_DETAILS_FAILURE,
          payload: err.message,
        });
      });
  };
  </code></pre>
  
  <blockquote>
    <p>My nginx config</p>
  </blockquote>
  
  <pre><code>  location /api/ {
      proxy_pass http://127.0.0.1:5000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }
  </code></pre>
  
  <blockquote>
    <p>Error Response  Error: Request failed with status code 404
        at createError (/home/ubuntu/mainWebApp/node_modules/axios/lib/core/createError.js:16:15)
        at settle (/home/ubuntu/mainWebApp/node_modules/axios/lib/core/settle.js:18:12)
        at IncomingMessage.handleStreamEnd (/home/ubuntu/mainWebApp/node_modules/axios/lib/adapters/http.js:202:11)
        at IncomingMessage.emit (events.js:198:15)
        at endReadableNT (_stream_readable.js:1139:12)
        at processTicksAndRejections (internal/process/task_queues.js:81:17)</p>
  </blockquote>