Port numbers not hiding in nginx reverse proxy (next js server) Port numbers not hiding in nginx reverse proxy (next js server) nginx nginx

Port numbers not hiding in nginx reverse proxy (next js server)


Try to change from

proxy_pass http://localhost:3000;

Into

proxy_pass http://127.0.0.1:3000;


Try with other applications in order to validate if something is wrong in your application.

Configure nginx to use domain instead ports are not complex. Just add https configurations but the main configurations will be the same.

Steps

  • npm install
  • node main_domain.js
  • node subdomain.js
  • Check if webs are working:

localhost

  • Add the following lines to your /etc/hosts. This will help us to use domains without enterprise web hosting company register.

127.0.0.1 maindomain.com127.0.0.1 subdomain.maindomain.com
  • Create a file in /etc/nginx/conf.d called maindomain.com.conf or whatever you want but with .conf

server {    listen 80;    server_name maindomain.com;        location / {        proxy_pass http://localhost:3000/;    }}
  • Create a file in /etc/nginx/conf.d called conf.d/subdomain.maindomain.com.conf or whatever you want but with .conf

server {    listen 80;    server_name subdomain.maindomain.com;        location / {        proxy_pass http://localhost:3001/;    }}
  • Restart the nginx

service nginx restart
  • And now, you could use a domain instead ip:port

domains