nginx 전단 분야 에서 의 응용
사실은 경량급 서버 로 역방향 프 록 시 와 부하 균형 을 잘 처리 할 수 있다.정적 자원 을 잘 처리 할 수 있다.그래서 우리 전단 에 도 잘 어 울 리 고 간단 해 요.우 리 는 주로 인터페이스 퍼 가기 (그리고 다른 일 들) 를 하 는 데 쓰 인 다.
nginx 명령 행
  sudo nginx 
   sudo nginx -t 
  
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
   sudo nginx -s reload
   sudo nginx -s (stop|quit|reopen)
 nginx 의 관건 은 설정 파일 의 설정 에 있 습 니 다. 안에 인자 가 많 습 니 다. 문 서 를 참조 할 수 있 습 니 다.여 기 는 우리 가 사용 할 수 있 는 것 만 소개 합 니 다.
    vim /etc/nginx/nginx.conf
    
    #      
    #user  nobody;
    #      ,              
    worker_processes  1;
    
    # error log     
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        #    worker             
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #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  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
        #   gzip  
        gzip  on;
        # gzip     javascript、         
        gzip_types text/plain application/x-javascript text/css text/javascript;
        
        #nginx    ,   1M;
        client_max_body_size 6m;
        
        #         
        include /etc/nginx/conf.d/*.conf;
        
        
        ####         ####
        server {
            listen       80;
            #    Domain
            server_name  10.142.78.40;
            #    
            root   E:\work;
            #      ,       
            autoindex on;
            #    /       index.html     index.htm
            index index.html index.htm;
            
            #  2      ,              
            default_type    ‘text/html’;
            charset utf-8;
            # header   _  
            underscores_in_headers on;
                  
           location ~(/usrcenter){
                    #    usrcenter,    http://10.142.78.40:8787/usrcenter
                    proxy_pass http://10.142.78.40:8787;
            }
            location /o2blog_wx/ {
                #    xxxx/o2blog_wx           http://127.0.0.1:3000
                #   rewrite    , o2blog_wx        
                #    xxxx/o2blog_wx/hello  =》  http://127.0.0.1:3000/hello
                proxy_pass http://127.0.0.1:3000;
                rewrite ^/o2blog_wx/(.*) /$1 break;
            }
            
            #   dist      /      
            location ~(/dist){
                   #         ,  dbeug;       
                  expires off; 
                  # expires 365d;
            }
            
            #  /   URL     /index.html 
            location / {
                     rewrite ^  /index.html break;
                     index index.html index.htm;
             }
             
             ##   302   
            location /o2blog_wx/ {
                #     http://aotu.jd.com/o2blog_wx/       http://aotu.jd.com/wxblog
                return 302 http://aotu.jd.com/wxblog
            }                                                   
            error_log /var/log/nginx/html_error.log;
            
            #  404  50X             
            error_page  404              /404.html;
            error_page   500 502 503 504  /50x.html;                
        }
    }
  nginx 전단 의 기타 용도
    set $env_id "1.1.1.1";
    if ( $http_cookie~* "host_id=(\S+)(;.*|$)") {
        set $env_id $1;
    }
    
    location / {
        proxy_set_header Host $host;
        proxy_pass   http://$env_id:80;
    }
  nginx 이용http_concat, 합병 요청, 이런 방식 으로http://example.com/??style1. css, style2. css, foo / style3. css 가 합 쳐 진 자원 에 접근 합 니 다.(아 리 계 에서 자주 사용 하 는 방법 이기 도 하 다)
ps: 포트 가 점용 되 었 는 지 확인 하기:
    sudo lsof -i :8090
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.