Let's say I have a Next.js Application. Which is working properly. The application is currently accessible through http://localhost:4000 or http://somehostname.local:4000
here, I have set
127.0.0.1 somehostname.local
in my hosts file.
But, I want this Next.js application to only be accessible from http://somehostname.local:4000 only, in my local environment.
How would I do it?
That's inevitable, in your hosts file the name
localhostis referencing the loop IP (127.0.0.1), which means your local environment.So even by using
somehostname.localwhich is a new name for the local area, thelocalhostexists.If you want to use
localhostfor another project, you can use a different port or default port (80) for another project.If that's your utter decision to have got
somehostname.localfor the current NextJs project andlocalhostfor another one even with the same port, you must install and use NGINX on your system to add policies that I won't proffer to you at all.