4

I have an EC2 instance with AWS and I have installed nginx and created multiple server blocks to server multiple applications.

However, if nginx goes down, all the applications go down as well.

Is there any way to setup seperate nginx instance for each application? So if one nginx instance goes down, it won't affect other instances.

Vinod Kumar
  • 1,479
  • 3
  • 13
  • 23

5 Answers5

4

Yes, its technically possible to install 2 nginx instances on the same server but I would do it another way.

1 - You could just create multiple EC2 instances. The downside of this approach is that maybe it's gets harder to maintain depending on how many instances you want.

2 - You could use Docker or any of its alternatives to create containers and solve this problem. You can create as many containers you need and totally separate nginx instances. Although docker is simple to learn and start using it in no time, the downside of this approach is that you need to put a little effort to learn it and your main EC2 instance needs to have enough resources to share between the containers.

I hope it helps!

  • you are probably right to look for a different solution in his usecase. But I also have the requirement to run 2 instaces of NGINX on one server in different versions. (How) is that possible? – Sauer Feb 01 '21 at 14:31
  • Hello @Sauer, in your case, the number 2 is the way I think it could be better. – Guilherme Assemany Feb 01 '21 at 14:34
  • again: this is true! But i am just "a guest" on this existing machine and cannot do whatever i want. – Sauer Feb 03 '21 at 15:42
4

If it's possible to use ELB instead of nginx. this will be more convenient but if ELB doesn't work for you. nginx already support High Availability mode to avoid the problem you mentioned of having a single point of failure it's documented officially here https://www.nginx.com/products/nginx/high-availability/ it's better than having one nginx machine for every application and grantee more availability

M.Elkady
  • 1,093
  • 7
  • 13
0

The type of redundancy that you’re looking for is usually provided by a load balancer or reverse proxy in practice. There’s a lot of ways this can be achieved architecturally, but generally speaking looks like this;

Run multiple nginx instances with the same server definitions, and a balancer like haproxy. This allows the balancer to check which nginx instances are online and send requests to each in turn. Then if a instance goes down, or the orchestrator is bring up a new one, requests only get sent to the online ones.

If requests need to be distributed more heavily, you could have nginx instances for each server, with a reverse proxy directed at each instance or node.

cawwot
  • 193
  • 9
0

There may be some overhead for nginx if you do it that way and your nginx may be difficult to maintain later because there are many nginx instances. Ex. If you need to update or add some modules it will be harder.

How about if you try using EC2 autoscaling group even a minimum 1 and desired 1? So that it will automatically launch a new instance if the current one goes down.

If you need to preserve some settings like the elastic ip of your EC2, you can try to search for EC2 instance recovery. It will restore your setup unlike the autoscaling group.

But it would be better if you will use a loadbalancer like ALB and use 2 instances at a minimum. Using an ALB will also make you more secure. You may also want to read about ALB target groups. It will give you more options on how to solve your current problem.

tungsten_carbide
  • 525
  • 5
  • 18
0

As long as you can use different ports for your nginx instances, check this post: https://serverfault.com/questions/1138876/how-can-you-run-two-instances-of-nginx-on-the-same-machine-without-docker

pkSML
  • 205
  • 2
  • 8