• nginx配置文件nginx.conf


    nginx安装后默认的配置文件为/usr/local/nginx/conf/nginx.conf,以下为默认配置文件的内容

    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        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;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        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;
            #}
        }
    
    
        # 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;
        #    }
        #}
    
    }
    默认nginx.conf内容

    nginx.conf配置文件由三部分组成

    1、全局块

    从配置文件开始到events之间的内容,主要会设置一些影响nginx服务整体运行的配置指令,包括运行nginx服务的用户/组、允许生成的worker process数、进程PID存放路径、日志存放路径和类型、配置文件的引入等。

    比方上述配置文件中的worker_processes  1,表示nginx并发处理的值,值越大表示并发处理的数越多。

    2、enents块

    主要影响nginx服务与用户的网络连接,常用的设置包括是否开启对多worker process下的网络连接进行序列化、是否允许同时接收多个网络连接、选取哪种事件驱动模型来处理连接请求、每个worker process同时支持的最大连接数等。

    比如上述配置文件中的worker_connections  1024,表示每个worker process支持的最大连接数为1024。

    3、http块

    nginx服务配置中最频繁修改的部分,代理、缓存、日志定义等绝大部分功能和第三方模块的配置都在这部分,包括http全局块和server块。

    3.1、http全局块

    包括文件引入、MIME-TYPE定义、日志自定义、连接超时时间、单链接请求数上限等。

    3.2、server块

    server块与虚拟主机有密切关系,每个http块可以包括多个server块,而每个server块就相当于一个虚拟主机,server块也分为全局server块和location块。

    3.2.1、server全局块

    最常见的是配置本虚拟机主机的监听配置和本虚拟主机的名称或ip配置。

    3.2.2、location块

    一个server块可以配置多个location块。主要作用是基于nginx服务接收到的请求字符串(例如server_name/uri-string),对虚拟主机名称(也可以是ip别名)之外的字符串(liru例如前面的/uri-string)进行匹配,对特定的请求进行处理。地址定向、数据缓存、应答控制、第三方模块配置等都在这里完成。

    即配置文件结构如下

    全局块
    
    events {
        events块;
    }
    
    http {
        http全局块;
    
        server {
            sever全局块;
    
            location / {
                location块;
            } 
            location ……{
                location块;
            }
        }
        server {
        
        }
    }
  • 相关阅读:
    C#中Split用法
    ASP.NET Get和Post两种提交的区别:
    BAT常用命令
    SQL语句:在两个数据库间复制表结构和数据数据库
    C#中Array与ArrayList用法及转换
    找出输入区间内的回文质数
    (转)加藤嘉一:中国大学生,你没资格抱怨政府
    最长公共子序列(LCS)
    shell(希尔)排序
    关于Ubuntu中google chrome浏览器字体的设置
  • 原文地址:https://www.cnblogs.com/Forever77/p/16029332.html
Copyright © 2020-2023  润新知