Hello,
I have a microservice project (Node.js) where each part is in a separate directory. I want to run this website through Nginx. By default, Nginx uses the /usr/share/nginx/html directory. I have two questions:
1- Should I copy all the project files to the /usr/share/nginx/html directory?
2- Should I create a directory for each project in the /usr/share/nginx/html directory and then use the location block in the Nginx configuration file?
Hi,
Thank you so much for your reply.
You right.
I have some questions:
1- Can I run microservices on my system for testing? What should I use instead of part1.example.com? Can I use something like part1.localhost.localhost?
2- I have several microservices in the container as follows:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cfd3dda07cfb yaml-Part1 "docker-entrypoint.s…" 20 hours ago Up 20 hours 0.0.0.0:3001->3000/tcp, :::3001->3000/tcp Microservice-1
2b1f111e106d yaml-Part2 "docker-entrypoint.s…" 20 hours ago Up 20 hours 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp Microservice-2
a50ed19dc560 yaml-Part3 "docker-entrypoint.s…" 20 hours ago Up 20 hours 0.0.0.0:3002->3000/tcp, :::3002->3000/tcp Microservice-3
I am not familiar with interpreted micro services, but a guess i to test locally you have to specify port. http://127.0.0.1:3000 if the service is running on port 3000. The name does not matter if you not is running via a DNS.
Hello,
Thanks again.
Other questions were raised to me:
1- Was my configuration wrong? Your configuration is different from mine.
2- So, if I can start all the microservices on the same IP address, then when I ping part1.example.com and part2.example.com they should have the same IP address. Right?
I use a compiled language with built in engine. I see you use Node.js so I guess that you can run several Node applications on different ports. Then it should not be that different from my Nginx settings.
Your VPS (or server) is like a telephone. Calling the main number (IP-address). To talk to the right person you ask the switchboard (Nginx) to connect to the correct port (direkt number).
I have never used /etc/hosts in this way before. IDK.
Have you tried to use http://serverip:portnumber in your browser instead of curl? Or you can try to confirm that Node is listening on a port on Debian (if you not use Debian or Ubuntu search for the exact command)
If you use a terminal at the server and sends curl localhost:3000 it is calling the Node directly without using the internet. If you call it from your computers browser you use the internet to contact Nginx which pass the request to Node at port 3000.
localhost never touches the internet and hence not the Nginx.
I am playing with micro services communicating on the same server only using localhost. Faster and less traffic (no internet or Nginx involved). And way safer.
Does not docker complicates things until you get it to work without containers? What is the purpose of containers in this phase? Will it not be simpler to add containers later? Just wondering…
Each layer of complexity makes most things harder to grasp. I use to make things extremely simple at the beginning in order to understand. Then I add complexity…
And after configured the DNS, modify server_name server1
to server_name server1.example.com etc
Some micro services you may want to reach via the internet (DNS), Other micro services that is only called internally do not need neither Nginx nor DNS. Just call them internally via