Nginx 다 중 키 프로필 설정 및 프로필 참조 범례

14115 단어 Nginx
한 서버 의 이전 nginx 서버 아래 에 많은 항목 이 달 릴 수 있 습 니 다. 많은 항목 을 같은 프로필 에 쓰 면 후기 에 보기 어렵 고 관리 하기 어 려 울 수 있 습 니 다.따라서 하위 프로필 을 저장 하 는 폴 더 를 새로 만 든 다음 주 프로필 nginx. conf 에서 이 하위 디 렉 터 리 를 도입 하면 됩 니 다.
nginx. conf 파일 설정 은 다음 과 같 습 니 다.
#       nginx          
#user  nobody;

##     nginx     worker process  ,   CPU     
worker_processes  4;

## worker         ,  "too many open files"  
#worker_rlimit_nofile 100000

##           
error_log logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

## pid         
pid        logs/nginx.pid;

events {
    ##       ,select、poll、epoll 
    use epoll;
    ##      ,          
    worker_connections  1024;
}

## http  
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  ,  1024Kb   
    gzip  on;
    gzip_min_length 1024;

    server {
        listen       8000;
        server_name  localhost;
        location / {
            root /mnt;
        }
    }

    server {
        listen       80;
        server_name  localhost;
#charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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   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;
        #}
    }
    ##           !!!
    include test—project/*.conf;
}


conf 폴 더 아래 test - project 폴 더 를 새로 만 든 다음 하위 설정 파일 xx. conf 를 안에 있 습 니 다.nginx. conf 파일 에 include 하위 설정 파일 을 사용 하면 됩 니 다.
test - project 의 하위 프로필 설정 은 다음 과 같 습 니 다.
##        ,  test-backend         ,       。
#    【127.0.0.1:9002】       
upstream test-backend {
    server 127.0.0.1:9002;    
}
## test-peoject       
server {
    ##     
    listen 99;
    ##     
    server_name localhost;
    ##      
    charset utf-8;
    ##     
    access_log logs/test-peoject.access.log main;
    ##     
    #error_log logs/test-peoject.error.log main;
    #          
    client_max_body_size 500m;
    #      
    deny 192.53.163.212;

    #【html/test-project】              
    index index.html;
    root html/test-project;    

    ##     
    location / {
        try_files $uri $uri/ @router;
        index  index.html index.htm;
    }
    ## VUE    
    location @router {
        rewrite ^.*$ /index.html last;
    }
    ##         
    location ~ ^(/static/) {
        access_log off;
        root html/test-project;
        expires 7d;
    }
    ##       ,       
    location ~ ^(/static/).+\.(jpg|jpeg|gif|png)$ {
        access_log off;
        root html/test-project;
        expires 15d;
    }
    ##           
    proxy_pass_request_headers on;
    ##           
    proxy_set_header Host $host;
    proxy_set_header X-Real_IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    ##       ,     test-backend(      )
    location /test-pro {
        proxy_pass http://test-backend;
    }
}

좋은 웹페이지 즐겨찾기