How does the nextjs handle SEO? I am trying to render page by invoking it directly (localhost:8080/about) from the browser, but NGINX is returning 404. The link to same page embedded in the home page is working but the page can not be loaded directly using URL. Are additional configurations needed either in NGINX or Nextjs app.
5
Answers
NextJS serves the site itself and doesn’t use nginx or Apache.
In your package.json file, you should have a
next
command in the scripts section. I normally have:Running
yarn dev
ornpm run dev
will bootstrap the site and allow you to connect to the site locally and see how it handles 404s and other errors.When you deploy your site, it will be using this kind of server set-up rather than either of the servers mentioned above.
I hope that’s helpful.
Could you share some configuration code?
Out of the box nextjs should display the default export react component that lives under pages/about.js or pages/about/index.js /about when hitting https://localhost:8080/about.
Since you’re using NGINX as your web server, you may want to reverse proxy to your NextJS app. https://medium.com/@deresegetachew/serving-react-spa-using-nginx-and-reverse-proxy-4e5485c814a0
React/NextJS uses port 3000 by default. Your URL in your post is pointing to port 8080. NGINX is not used by NextJS by default, so I believe a different web server is rendering your page, i.e. NGINX.
When you run the following commands on your nextjs project, you’ll see the following output and it’ll say what port is being served. Then try viewing that with your web browser.
If your have a server.js in your projects top directory, or you can add one to configure which port your app will serve. https://nextjs.org/docs/old#custom-server-and-routing
If your web server has a firewall enabled, not all ports will be available.
Next.Js has it’s on server so you don’t have to use another one.
Just run the command
npm run dev
after installing the next.js using the command prompt for running locally in you machine.maybe you run application on port 3000 and when you want to serve on another port for example 80 or 8080, you need redirect Nginx requests to port 3000 in this way that you make redirection in Nginx’s config file :
(replace server-ip with your server ip or localhost or 127.0.0.1)
although you can run
PM2
for manage and run your application on the server easilyas I saw your nginx serve nothing on 8080 port, that’s why you didn’t reach to your application on
http://localhost:8000
, so you can test withhttp://localhost:3000
because default port is 3000that’s all it.