docker Nginx (2) 부하 균형 설정
                                            
 2549 단어  docker
                    
우선
docker cp 65ed8999c4d3:/etc/nginx/nginx.conf ~/nginx_temp/conf 명령 으로 용기 에 있 는 /etc/nginx/nginx.conf 파일 과 /etc/nginx/conf.d/default.conf 파일 을 이 컴퓨터 ~/nginx_temp (ps: 상황 에 따라 설정 을 변경 할 수 있 습 니 다) 에 복사 합 니 다.설정 수정
부하 균형 목적 을 달성 하기 위해 서 는 이 컴퓨터
~/nginx_temp/conf/conf.d/default.conf 파일 을 수정 하고 server 외부 증 가 를 저장 해 야 합 니 다.upstream web {
        server 192.168.1.6:8081 weight=5;
        server 192.168.1.6:8082 weight=1;
}
  서버 에 추가
location = / {
        proxy_pass http://web;
}
  default.conf 소스 코드upstream web {
        server 192.168.1.6:8081 weight=2;
        server 192.168.1.6:8082 weight=1;
}
server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    #location / {
    #    root   /usr/share/nginx/html;
    #    index  index.html index.htm;
    #}
    location = / {
        proxy_pass http://web;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
  실행 용기
docker run -d -p 81:80 --name nginx-server-1 \
-v ~/nginx_temp/www:/usr/share/nginx/html \
-v ~/nginx_temp/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
-v ~/nginx_temp/conf/nginx.conf:/etc/nginx/nginx.conf \
-v ~/nginx_temp/logs:/var/log/nginx nginx
  테스트
브 라 우 저 실행
192.168.1.6 시험 기 ip 입 니 다. 호스트 마다 ip 를 교체 하면 됩 니 다. 브 라 우 저 에서 다음 명령 을 수행 합 니 다.http://192.168.1.6:81
  테스트 후
8081 와 8082 포트 가 폴 링 에 접근 하고 있 음 을 발견 할 수 있 습 니 다. 그러면 nginx 로 부하 균형 서 비 스 를 간단하게 실현 할 수 있 습 니 다.
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swarm의 도커 비밀이 게시물에서는 Redis를 사용한 실제 시나리오 예제를 제공하여 사용 방법을 보여주고자 합니다. Docker 기술에 대한 기본 지식 Docker Swarm 오케스트레이터에 대한 기본 지식 "Docker Swarm ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.