nginx 프로필

5768 단어
본 고 는 nginx 기본 설정 파일 nginx. conf 의 대부분의 명령 을 보 여 주 었 고 중국어 주석 설명 을 추가 하 였 습 니 다. 실제 설정 에 서 는 이렇게 복잡 하지 않 을 수 있 습 니 다. 여 기 는 참고 로 문 서 를 읽 을 수 있 습 니 다!nginx 기본 설정
 
  
# Nginx , , nologin
user www www;  
# , cpu
worker_processes  1;

# PID
error_log  /var/log/nginx/error.log; # ,[ debug | info | notice | warn | error | crit ]
pid        /var/run/nginx.pid;

# nginx , ( ulimit -n) nginx , nginx , ulimit -n 。
worker_rlimit_nofile 65535;

#
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/*;


   #
   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;
        }

     }
}


2. nginx 의 부하 균형 과 프 록 시 설정
 
  
# 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

       }

     }
}

좋은 웹페이지 즐겨찾기