docker 설치 nginx

18296 단어
첫 번 째 배치 방안 은 docker 를 직접 사용 합 니 다.
주의:
docker 용기 와 호스트 를 동기 화 하 는 시간
              
1)     localtime
             ,  localtime      ,              。
# docker run -ti -d --name my-nginx -v /etc/localtime:/etc/localtime:ro  docker.io/nginx  /bin/bash
 
2)     localtime
[root@slave-1 ~]# docker cp /etc/localtime 87986863838b:/etc/

Docker 배포 nginx
1. Nginx 미 러 설치
[root@application ~]#   docker pull nginx                   #                 

[root@application ~]#  docker images                        #   ,   docker images    nginx   

2. 용 기 를 시작 하기 전에 맵 이 필요 한 파일 경 로 를 만 듭 니 다.
[root@application ~]#   mkdir -p   /usr/local/nginx/www   /usr/local/nginx/logs  /usr/local/nginx/conf

3. nginx. conf 설정 파일 만 들 기
#     vim /usr/local/nginx/conf/nginx.conf

아래 프로필 을 프로필 에 붙 여 넣 기
worker_processes  1;
events {
    worker_connections  1024;  #    worker process          
}
http {
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        # Vue     history      
        location / {
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.html?s=$1 last;
                break;
            }
            root   /usr/share/nginx/html;
            index  index.html;
        }

        #     IP  Websocket      
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        #    Body    (          )
        client_max_body_size 5m;

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

4. 방화벽 설정 80 포트 변경
#        
[root@application ~]# systemctl start firewalld
#        
[root@application ~]# systemctl status firewalld

#                 
[root@application ~]#  firewall-cmd --zone=public --add-port=80/tcp --   #       
[root@application ~]#  firewall-cmd --reload        #              
[root@application ~]#   firewall-cmd --zone=public --query-port=80/tcp   #        

5. nginx 미 러 시작
#  docker        
docker run -it -d --name mynginx -p 80:80 -v /usr/local/nginx/www:/usr/share/nginx/html -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/logs:/var/log/nginx 
-v /etc/localtime:/etc/localtime:ro --privileged --net=host --restart=always nginx:latest

#               ----      
docker run -it -d --name mynginx -p 80:80
-v /etc/localtime:/etc/localtime:ro                       #            
-v /usr/local/nginx/www:/usr/share/nginx/html             #    www      html    
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf #      
-v /usr/local/nginx/logs:/var/log/nginx  				#         
--privileged --net=host --restart=always nginx:latest

6. NGINX 상세 프로필
#    
user www-data;    
#    ,      cpu     
worker_processes  1;

#       PID  
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

#          
events {
    use   epoll;             #epoll     IO(I/O Multiplexing)      ,     linux2.6    ,      nginx   
    worker_connections  1024;#    worker process          
    # multi_accept on; 
}

#  http   ,                  
http {
     #  mime  ,   mime.type    
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    #      
    access_log    /var/log/nginx/access.log;

    #sendfile      nginx      sendfile   (zero copy   )     ,      ,
    #     on,             IO     ,     off,        I/O    ,     uptime.
    sendfile        on;
    #tcp_nopush     on;

    #      
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
    
    #  gzip  
    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    #      
    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    #            
     upstream mysvr {
    #weigth      ,             
    #    Squid  3128  
    server 192.168.8.1:3128 weight=5;
    server 192.168.8.2:80  weight=1;
    server 192.168.8.3:80  weight=6;
    }


   server {
    #  80  
        listen       80;
        #    www.xx.com  
        server_name  www.xx.com;

        #            
        access_log  logs/www.xx.com.access.log  main;

    #    
    location / {
          root   /root;      #               
          index index.php index.html index.htm;   #           

          fastcgi_pass  www.xx.com;
         fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name; 
          include /etc/nginx/fastcgi_params;
        }

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

    #    ,nginx    
    location ~ ^/(images|javascript|js|css|flash|media|static)/ {
        root /var/www/virtual/htdocs;
        #  30 ,         ,        ,      ,         。
        expires 30d;
    }
    #PHP           FastCGI  .   FastCGI    .
    location ~ \.php$ {
        root /root;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
        include fastcgi_params;
    }
    #    Nginx     
    location /NginxStatus {
        stub_status            on;
        access_log              on;
        auth_basic              "NginxStatus";
        auth_basic_user_file  conf/htpasswd;
    }
    #     .htxxx   
    location ~ /\.ht {
        deny all;
    }
     
     }
}

7. 부하 균형 을 사용 하려 면 http 노드 를 다음 과 같이 수정 할 수 있 습 니 다.
#  http   ,                  
http {
     #  mime  ,   mime.type    
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    #      
    access_log    /var/log/nginx/access.log;

    #            

    #。。。。。。。。。。

    #            
     upstream mysvr {
    #weigth      ,             
    server 192.168.8.1x:3128 weight=5;#    Squid  3128  
    server 192.168.8.2x:80  weight=1;
    server 192.168.8.3x:80  weight=6;
    }

   upstream mysvr2 {
    #weigth      ,             

    server 192.168.8.x:80  weight=1;
    server 192.168.8.x:80  weight=6;
    }

   #        
   server {
    #  192.168.8.x 80  
        listen       80;
        server_name  192.168.8.x;

      # aspx           
    location ~ .*\.aspx$ {

         root   /root;      #               
          index index.php index.html index.htm;   #           

          proxy_pass  http://mysvr ;#    mysvr         

          #               .

          proxy_redirect off;

          #   Web       X-Forwarded-For      IP
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          client_max_body_size 10m;    #                
          client_body_buffer_size 128k;  #                  ,
          proxy_connect_timeout 90;  #nginx            (      )
          proxy_send_timeout 90;        #           (      )
          proxy_read_timeout 90;         #     ,         (      )
          proxy_buffer_size 4k;             #       (nginx)             
          proxy_buffers 4 32k;               #proxy_buffers   ,     32k    ,    
          proxy_busy_buffers_size 64k;    #        (proxy_buffers*2)
          proxy_temp_file_write_size 64k;  #         ,     ,  upstream    

       }

     }
}

두 번 째 배치 방안
docker compose 배치 nginx 사용 하기

좋은 웹페이지 즐겨찾기