I am using a reverse proxy and load balancing. In my scenario, I have three servers. The first server is the proxy. The second and third are docker servers that use swarm. Port 2020 is used for two replicas of the Apache service. Port 2021 is used for two replicas of the Nginx service. The balancing is done according to the replicas. As I am new to Nginx I was wondering if the following settings are enough. Would it be possible to improve this configuration? Is it safe?
proxy_config.conf:
##########
# Apache #
##########
upstream apache {
least_conn;
#Container replicas
server 192.168.0.4:2020;
server 192.168.0.5:2020;
}
server {
listen 80;
server_name host.apache.domain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://apache;
}
}
#########
# Nginx #
#########
upstream nginx {
least_conn;
#Container replicas
server 192.168.0.4:2021;
server 192.168.0.5:2021;
}
server {
listen 80;
server_name host.nginx.domain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://nginx;
}
}
In this specific case, I used the following:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://nginx;
}
If I only used the following configuration, wouldn't it be enough?
location / {
proxy_pass http://nginx;
}
I read the Nginx documentation, but I need more examples.