【Nginx】Nginx配置文件解析


默认配置文件路径:/usr/local/nginx/conf

主配置文件:/usr/local/nginx/conf/nginx.conf

主配置文件框架(nginx.conf) 配置文件的要求是每句结束必须要有分号;,花括号也必须是成对的

#user  nobody;    使用什么用户来运行nginx
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 pid存放位置,/usr/local/nginx/logs/nginx.pid


events {
    worker_connections  1024;    并发数,默认是1024,并发数和内核参数有关,内核参数openfile默认也是1024,内存参数限制了并发数
}


http {    网站
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    记录log日志的格式,默认最好不要修改
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;    访问access_log日志的位置

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;    页面压缩

    server {    一个server{}就是一个网页服务,如果配置文件里边没有了server{},那么启动nginx是无法访问网页
        listen       80;    监听端口,默认80
        server_name  localhost;    域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {    匹配路径,在访问http://127.0.0.1/时候就是匹配这个配置中的location /{},匹配到就返回location / {}花括号里边的内容,一个server{}能有多个location{};同样的,在地址栏输入http://127.0.0.0/test 匹配的是配置文件里边的location /test{} 
            root   html;    网页目录,安装路径下的html  /usr/local/nginx/html
            index  index.html index.htm;    默认首页,访问http://127.0.0.1/是时返回的页面
        }

        #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结尾的动态页面
        #    root           html;   动态页面位置
        #    fastcgi_pass   127.0.0.1:9000;    当匹配到了转发给本机的9000端口来处理
        #    fastcgi_index  index.php;    默认首页
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi.conf;    加载外部配置文件
        #}

        # 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 {    一个server{}就是一个网页服务,这里的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;    加密网站HTTPS,443端口
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;   公钥、证书的文件名,不写路径默认是在/usr/loca/nginx/conf/目录
    #    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;   主页面
    #    }
    #}

}

猜你喜欢

转载自www.cnblogs.com/BadManWM/p/12182449.html