This is my first time with nginx so please be gentle, i have two apache on two separate machines and a virtual host on each and i can access the pages from a LAN. i want to run nginx on another machine as a reverse proxy for them and do a load balncing for the two servers is that possible? and how the configuration will be like? i know i shouldn't ask this but i am new and i have been reading the basic nginx configuration from different sites but i couldn't understand anything, so basically i don't know how to configure it.


First you must set public ip or port forwarding from public ip, port 80, to your nginx server.

Then you must have connection between nginx and apache 1, between nginx and apache 2 and between apache 1 and apache 2.

                  | port 80 | prublic ip or fw from public ip
              |        nginx        |
             /           \
            /             \
    |---------|                  |---------|
    | apache1 |------------------| apache2 |
    |---------|                  |---------|

Connection between nginx and apache is user for load balancing

Connection between apach 1 and apache 2 is for app replication. You must have the same, synced, app on both apache node.

The following load balancing mechanisms (or methods) are supported in nginx:

round-robin — requests to the application servers are distributed in a round-robin fashion,

least-connected — next request is assigned to the server with the least number of active connections,

ip-hash — a hash-function is used to determine what server should be selected for the next request (based on the client’s IP address). Default load balancing configuration

The simplest configuration for load balancing with nginx may look like the following:

http {
upstream myapp1 {
    server apache1.example.com;
    server apache2.example.com;

server {
    listen 80;

    location / {
        proxy_pass http://myapp1;

More example of configuration and posibilitis you can find here

  • Then, accept answer – 2707974 Mar 31 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.