自己通过注释来学习nginx配置。

258 阅读1分钟

power by www.phpStudy.net

#user nobody;

#nginx进程 一般设置为何CPU核数一样

worker_processes 1;

#错误日志存放目录

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#进程pid存放位置

#pid logs/nginx.pid;

#工作模式及连接数上限

events { #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能 worker_connections 1024;#;单个后台worker process进程的最大并发链接数 }

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

fastcgi_connect_timeout 300;#指定nginx与后端fastcgi server连接超时时间

fastcgi_send_timeout 300;#指定nginx与后端fastcgi server传送响应时间

fastcgi_read_timeout 300;#指定nginx与后端fastcgi server响应超时时间

fastcgi_buffer_size 128k;#指定nginx读取fastcgi响应第一部分需要用多大的缓冲区,这个值表示将使用一个64kb的缓冲区响应第一部分应答(应答头)可以设置为fastcgi_buffers缓存区大小

fastcgi_buffers 4 128k; fastcgi_busy_buffers_size 256k; #整个数据请求需要多大的缓存区,建议设置为fastcgi_buffers值的两倍 fastcgi_temp_file_write_size 256k;#写入缓存文件使用多大的数据块,默认值是fastcgi_buffer值的2倍

#gzip on; gzip on; #开启压缩功能 gzip_min_length 1k; #设置允许压缩的页面最小字节数 gzip_buffers 4 32k; #压缩缓冲区大小 gzip_http_version 1.1; #压缩版本 gzip_comp_level 2; #压缩比率,1压缩比最小,处理速度更快 gzip_types text/plain application/x-javascript text/css application/xml; #用来指定压缩的类型 gzip_vary on; #squid缓存经过nginx压缩的数据 gzip_disable "MSIE [1-6].";

#设置请求缓存

server_names_hash_bucket_size 128; client_max_body_size 100m; client_header_buffer_size 256k; large_client_header_buffers 4 256k;

server {
    listen       80;  #监听端口
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
    root   "D:/phpStudy/WWW";  #站点根目录,即网站程序存放目录
    location / {
        index  index.html index.htm index.php l.php; #首页排序
       autoindex  off;
    }

    #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(.*)$  {
    #符合PHP扩展名的请求调度到fcgi server
        fastcgi_pass   127.0.0.1:9000; #抛给本机的9000端口
        fastcgi_index  index.php; #设定动态首页
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

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


# HTTPS server
#
#server {
#    listen       443;
#    server_name  localhost;

#    ssl                  on;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers   on;

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

include vhosts.conf;

}