$ cd /etc/nginx

$ sudo vi nginx.conf

 ( sites-available/ 디렉토리 내에 설정파일에 추가하지 않고 /etc/nginx/nginx.conf 설정파일에서 바로 수정)

 

[TCP] 

ex) mqtt

stream {
    upstream stream_backend {
        server 192.168.0.111:1883;
    }
    
    server {
        listen        1883;
        proxy_pass    stream_backend;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
}

 

[UDP]

stream {
    
    upstream udp_servers {
        least_conn;
        server 192.168.136.130:2000;
        server 192.168.136.131:2000;
        server 192.168.136.132:2000;
    }

    server {
        listen     2000 udp;
        proxy_pass udp_servers;
    }   
}

 

 

vi /etc/nginx/nginx.conf

events {}

http {	
	upstream backend {
		server 192.168.0.100:8889;
	}

	server {
		listen 80;
		
		location / {
			proxy_pass http://backend;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Host $http_host;
		}
	}

	upstream backend_api {
		server 192.168.0.100:7000;
	}

	server {
		listen 7000;
		
		location / {
			proxy_pass http://backend_api;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Host $http_host;
		}
	}
}
 
stream {
    upstream stream_backend {
        server 192.168.0.100:1883;
    }
    server {
        listen        1883;
        proxy_pass    stream_backend;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }    

    upstream udp_servers {
        server 192.168.0.100:2000;
    }
    server {
        listen     2000 udp;
        proxy_pass udp_servers;
    }

    upstream udp_servers1 {
        server 192.168.0.100:2001;
    }
    server {
        listen     2001 udp;
        proxy_pass udp_servers1;
    }
 
    upstream udp_servers2 {
        server 192.168.0.100:2002;
    }
    server {
        listen     2002 udp;
        proxy_pass udp_servers2;
    }
	
}

 

 

'Infra Structure > Nginx' 카테고리의 다른 글

[Linux] Nginx offline 설치  (1) 2022.10.24
[Nginx] 무중단 배포  (0) 2022.07.13
[Nginx] SSL 적용  (0) 2022.07.11
[Nginx] docker로 Nginx 설치  (0) 2022.07.03
[Nginx] Load Balancing 설정하기  (0) 2022.06.01

+ Recent posts