nginx配置文件nginx.conf详细讲解(1)

14 篇文章 1 订阅

在实际工作中,我们很多的时候都会用到nginx做相应的代理服务,有的童鞋和我反馈,经理(laoshi),我总是记不住nginx配置文件中应该如何配置,nginx.conf中都有哪些模块配置内容,如何配置呢?

在这里插入图片描述

好,为了方便大家理解,我来为大家分四章节来讲解这个问题。

1.nginx安装完毕后自动生成的nginx.conf配置文件。

在这里插入图片描述
注意:这里我们使用安装的nginx版本为1.15.12版本,若版本不同,可能存在配置文件内容不一样的情况,请注意。
在这里插入图片描述

2.配置文件内容记录

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

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

}

3.配置文件模块讲解

根据配置文件的内容,我们不难看出,conf配置文件中分类为如下几大模块:main、events、http、server 、location。

其实我们常用的要比目前体现出的模块更多,还多了stream、upstream模块。是不是听起来感觉还是有点多,记不住,好,我们来看一张图(鄙人亲自所画的图),本来是针对于技术的讲解的很正规的一个conf架构图的内容,结果画画就淘气的画成了这样。
在这里插入图片描述
反正我看起来像个猪八戒的画像,好像是画的跑偏了,不管了,谁让鄙人的画画水准太次呢。。。
在这里插入图片描述
不过我到是认为这样看起来记忆会更加深刻些。好,今天就到这,下章我们来正经的讲下基于此图的各个模块的详细内容。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值