Nginx

로드밸런싱 설정

ZzangHo 2022. 1. 27. 11:24
728x90

Nginx에서 로드밸런싱 설정을 해보자

[root@hostname ~]# cd /etc/nginx/
[root@hostname nginx]# vi nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
 
...
 
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
...
 
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
 
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;      <-- 해당 경로로 이동
 
...
 
# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name
[root@hostname nginx]# cd conf.d/
[root@hostname conf.d]# pwd
/etc/nginx/conf.d
[root@hostname conf.d]# vi proxy.conf
 
## 아래 설정 추가
## 아래 ip를 입력해 준다
upstream elasticSearch {
    server {ip1}:9200;
    server {ip2}:9200;
    server {ip3}:9200;
}
 
server {
    listen 80;
 
    location / {
        proxy_pass http://elasticSearch;
    }
}

 

위와 같이 구성을 해준 뒤 해당 서버로 80포트로 접속을 하면 된다.

'Nginx' 카테고리의 다른 글

Nginx 성능 튜닝  (0) 2022.01.27
Nginx 설치  (0) 2022.01.27