centos 7 nginx 설치 및 설정 부하 균형 실현

5055 단어 Centos 7 시리즈
이 글 은 더 이상 업데이트 되 지 않 습 니 다. 최신 버 전의 글 과 더 많은 내용 을 보십시오.
오른쪽 단 추 를 누 르 면 새 탭 에서 링크 를 열 수 있 습 니 다.
《 centos 7 nginx 설치 와 설정 부하 균형 실현 》
 
분할선
nginx 는 apache 와 같은 웹 서버 이지 만 apache 보다 성능 이 좋 고 빠르다.또한 역방향 에이전트 와 부하 균형 을 실현 하여 웹 서비스 클 러 스 터 의 부하 균형 을 구축 하 는 데 자주 사용 된다.오늘 은 nginx 의 설치 와 설정 을 기록 하여 부하 균형 을 이 루 는 역할 을 합 니 다.1. 우선, 설치
#       epel-release 
$ rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

#   yum  nginx
$ yum install nginx


#          ,     ,     systemctl   nginx    
#       
$ systemctl enable nginx

#   nginx
$ systemctl start nginx

#     
$ systemctl status nginx

2. 프로필 수정   nginx 설정 파일 을 설정 하여 부하 균형 을 실현 합 니 다.말 그대로 여러 요 구 를 서로 다른 서비스 에 나 누 어 균형 적 인 부 하 를 실현 하고 하나의 서비스의 압력 을 줄 이 는 것 이다.
#        
$ vim /etc/nginx/nginx.conf
----------------------------------------------------------------------------------
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/


user nginx;
#      ,     ,      ,     cpu  
worker_processes auto;
#       
error_log /var/log/nginx/error.log;
# pid    
pid /run/nginx.pid;


# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;


events {
    #     , linux2.6  ,  epoll  , Linux 2.6             I/O  
    use epoll;
    #          ,        ,   on
    accept_mutex on;
    #                   ,   off
    multi_accept on;
    #           
    worker_connections 1024;
}


http {
    #     ,     main
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #                 
    access_log  /var/log/nginx/access.log  main;

    #       
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    #       
    keepalive_timeout   65;
    types_hash_max_size 2048;

    #     
    gzip on;
    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;


    #         ,         ,nginx      ,  ,ip-hash,       。
    #      http  ,      。
    #              ,       
    # ip-hash,  ip   ,     ip         。
    #     ,      nginx      ,              ,        

    # tomcat            ,      upstream
    upstream tomcat {
        # ip_hash  ip-hash  
        ip_hash;
        # weight   
        server 192.168.14.132:8080 weight=5;
        server 192.168.14.133:8080 weight=3;
    }




    server {
        #     
        listen       80 default_server;
        #      
        server_name  _;
        root         /usr/share/nginx/html;


        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

    
        #          ,                         
        location / {
          #     ,             
          proxy_pass    http://tomcat;
          proxy_redirect off; 
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          
          #               ,   
          proxy_connect_timeout 90;
          proxy_send_timeout 90;
          proxy_read_timeout 90;
        }
   
   # location ~\.(gif|jpg|png)$ { (  ,       )  
   #  root /home/root/images;
   #  }


        error_page 404 /404.html;
            location = /40x.html {
        }


        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }


# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }


}
----------------------------------------------------------------------------------


#      ,        ,       
$ systemctl reload nginx

 
OK, 여기 서 nginx 의 설치 와 부하 균형 을 완 성 했 습 니 다.기다 리 세 요. 궁금 한 점 이나 질문 이 있 으 시 면 댓 글 을 남 겨 주세요.

좋은 웹페이지 즐겨찾기