zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Nginx主配置文件各参数说明——筑梦之路

Nginx配置文件 参数 说明 筑梦之路
2023-09-14 09:09:36 时间
Nginx主配置文件模板说明
# 由谁来执行worker,master是由root执行的
# 默认是由nobody来执行worker
#user  nobody;

# worker进程数量,和cpu数量相关的,一般是cpu核心数 - 1
worker_processes  2;

# nginx 日志级别 从低到高
# debug info notice warn error crit
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

# nginx 进程号
#pid        logs/nginx.pid;


# 事件处理
events {
    # 默认使用epoll,windows 系统用不了,这个是使用linux 的epoll,处理异步请求的,容纳更高的并发
    # use epoll;
    # 每个worker允许连接客户端的最大连接数
    worker_connections  1024;
}


# http相关网络传输指令块
http {
    # 导入外部的配置,提高可读性;mime.types 是外部文件,相对路径,和nginx.conf这个核心配置在同一个文件夹下面
    include       mime.types;

    # 默认的类型
    default_type  application/octet-stream;

    # 记录日志的格式,access_log文件里
    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;

    # 用于文件高效传输,提升nginx性能
    sendfile        on;
    # 只有sendfile开启了,才可以用,当数据包达到一定数目,才开始传输
    #tcp_nopush     on;

    # 客户端连接服务器的超时时间,以s为单位的,保证客户端多次请求不会建立重复连接
    # 打开会占用一丢丢资源
    #keepalive_timeout  0;
    keepalive_timeout  65;

    # 启用压缩,html/js/css压缩之后,传输更快,节约带宽
     gzip  on;
    # 限制最小压缩,小于1个字节的文件不会压缩
     gzip_min_length 1;
    # 定义压缩级别 (压缩比,文件越大,压缩越多,但是cpu使用会越多)
     gzip_comp_level 3;
    # 定义压缩文件的类型
     gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jepg image/gif image/png application/json;

    server {

        # 监听80端口
        listen       88;

        # server_name 就是ip或者域名
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # 映射
        location / {
            # root 请求位置
            root   html;
            # index 首页设置
            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;
        #}
    }

    # 导入architect.conf文件
    include architect.conf;

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

}