nginx配置文件nginx.conf详细讲解(1)
发布日期:2021-05-07 10:54:51 浏览次数:22 分类:精选文章

本文共 3112 字,大约阅读时间需要 10 分钟。

在实际工作中,我们很多的时候都会用到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架构图的内容,结果画画就淘气的画成了这样。

在这里插入图片描述
反正我看起来像个猪八戒的画像,好像是画的跑偏了,不管了,谁让鄙人的画画水准太次呢。。。
在这里插入图片描述
不过我到是认为这样看起来记忆会更加深刻些。好,今天就到这,下章我们来正经的讲下基于此图的各个模块的详细内容。

上一篇:第六章 Json和AJAX
下一篇:netstat命令提示不存在

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月02日 02时07分13秒