Nginx简单配置

user  www;    #工作进程用户,默认是nobody
worker_processes  1;    #工作进程数量,一般等于cpu核数

#error_log  logs/error.log;    #定义错误日志路径,后面可以跟错误级别
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;    #nginx进程运行文件地址


events {
    accept_mutex on;    #防止进程惊群效应,默认开启
    use epoll;    #I/O多路复用,事件驱动模型
    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;    #开启高效文件传输模式,如果提供下载服务建议设置为off
    #tcp_nopush     on;    #设置数据包中发送所有头文件,而不是一个一个发送,防止网络阻塞

    #keepalive_timeout  0;
    keepalive_timeout  65;    #客户端连接保持时间,超过这个时间断开连接
    keepalive_requests 10240;    #HTTP长连接最多处理完成的最大连接数,达到最大请求书好欧关闭连接
    tcp_nodelay on;    #防止网络阻塞
    client_header_buffer_size 4k;    #客户端请求头部的缓冲区大小
    open_file_cache max=102400 inactive=20s;    #打开文件指定缓存,max指定缓存数量,inactive指定文件未请求多久删除缓存
    open_file_cache_valid 30s;    #多久检查缓存有效信息
    open_file_cache_min_uses 1;    #指定open_file_cache中inactive参数时间内文件最少使用次数
    client_header_timeout 15;    #设置请求头的超时时间
    client_body_timeout 15; #设置请求内容的超时时间
    reset_timedout_connection on;    #关闭不响应的客户端连接
    send_timeout 15;    #响应客户端超时时间
    server_tokens off;    #关闭错误页面中的nginx版本数字
    client_max_body_size 10m;    #上传文件大小限制

    #fastcgi
    fastcgi_connect_timeout 600;    #连接后端FastCGI超时时间
    fastcgi_send_timeout 600;    #向FastCGI传送请求的超时时间
    fastcgi_read_timeout 600;    #接收FastCGI应答的超时时间
    fastcgi_buffer_size 64K;    #读取FastCGI应答第一部分缓冲区大小
    fastcgi_buffers 4 64k;    #本地需要多少和多大的缓冲区缓冲FastCGI的应答请求
    fastcgi_busy_buffers_size 128k;    #系统繁忙时的buffer,一般是fastcgi_buffers的两倍
    fastcgi_temp_file_write_size 128k;    #在写入fastcgi_temp_path时数据块的大小,默认是fastcgi_buffers的两倍
    fastcgi_temp_path /usr/local/nginx/nginx_tmp;    #FastCGI服务器临时接收目录
    fastcgi_intercept_errors    on;    #是否允许nginx使用error_page处理错误信息
        


    gzip  on;    #开启gzip压缩功能
    gzip_min_length 1k;    #允许压缩的页面最小字节数
    gzip_buffers 4 32k;    #压缩缓冲区大小,表示申请4个单位为32K的内存作为压缩结果流缓存
    gzip_http_version 1.1;    #压缩版本
    gzip_comp_level 6;    #压缩比例
    gzip_types text/css text/xml application/javascript;   #指定压缩类型
    gzip_vary on;    #让前端的缓存服务器缓存经过GZIP压缩页面


    #虚拟主机配置
    server {
        listen       80;  #监听端口
        server_name  www.ng.com ng.com;  #虚拟主机域名

        charset utf-8;    #默认编码

        #access_log  logs/host.access.log  main;  #请求日志路径及格式

    #
        location / {
            root   html;  #网站根目录
            index  index.php index.html index.htm;  #首页手机文件名称
        }

        #error_page  404              /404.html;  #404错误页面地址

        # redirect server error pages to the static page /50x.html  #错误页面重定向
        #
        error_page   500 502 503 504  /50x.html;  #500  502 503 504错误页面
        location = /50x.html {
            root   html; #59x.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
        # 将php请求转发到fastcgi处理
        location ~ \.php$ {
            root           /usr/local/nginx/html;  #根目录
            fastcgi_pass   127.0.0.1:9000;  #将请求转发给哪个服务器的哪个端口
            fastcgi_index  index.php;  #指定默认首页文件
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  #脚本文件请求路径
            include        fastcgi_params;  #加载更多fastcgi_params映射
        }

    #图片等文件缓存时间    
    location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ {
          expires 30d;
          access_log off;
       }

    #js css文件缓存时间
    location ~* \.(js|css)$ {
        expires 7d;
        log_not_found off;
        access_log off;
    }     

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        # 精致访问.ht开头文件
        #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 ssl;
    #    server_name  localhost;

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

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

 

posted @ 2020-08-22 16:48  事儿爸_董  阅读(112)  评论(0编辑  收藏  举报