Nginx 配置文件解析

一、配置文件目录

        Nginx配置文件在conf目录下,其默认目录结构如下。 

        其中,以“.default”为扩展名的文件是Nginx配置文件的配置样例文件。各配置文件的说明如下。

  • fastcgi_params:Nginx在配置FastCGI代理服务时会根据fastcgi_params文件的配置向FastCGI服务器传递变量,该配置文件现已由fastcgi.conf代替。
  • fastcgi.conf:为了规范配置指令SCRIPT_FILENAME的用法,引入FastCGI变量传递配置。
  • mime.types:MIME类型映射表,Nginx会根据服务端文件后缀名在映射关系中获取所属文件类型,将文件类型添加到HTTP消息头字段“Content-Type”中。
  • nginx.conf:Nginx默认的配置入口文件。
  • scgi_params:Nginx在配置SCGI代理服务时会根据scgi_params文件的配置向SCGI服务器传递变量。
  • uwsgi_params:Nginx在配置uWSGI代理服务时会根据uwsgi_params文件的配置向uWSGI服务器传递变量。
  • koi-utf、koi-win、win-utf:这3个文件是KOI8-R编码转换的映射文件,因为Nginx的作者是俄罗斯人,在Unicode流行之前,KOI8-R是使用最为广泛的俄语编码。

二、配置文件结构

        打开系统默认的nginx.conf文件,可以看到整个文件的结构如下:

[root@003 ~]# vim /usr/local/nginx/conf/nginx.conf


#user  nobody;  #启动子进程程序默认用户
#一个主进程和多个工作进程。工作进程是单进程的,且不需要特殊授权即可运行;
这里定义的是工作进程数量。cpu多少核,就可以写多少
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服务设置
http {
    # 设定mime类型,有mime.type文件定义
    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"';
    
    #$remote_addr与$http_x_forwarded_for:用以记录客户端的ip地址;
    #$remote_user:用来记录客户端用户名称;
    #$time_local:用来记录访问时间与时区;
    #$request: 用来记录请求的ur1与http协议;
    #status:用来记录请求状态;成功是200,
    #$body_bytes_sent:记录发送给客户端文件主体内容大小;
    #$http_referer:用来记录从那个页面链接访问过来的;
    #$http_user_agent:记录客户浏览器的相关信息;

    # 全局访问日志路径
    #access_log  logs/access.log  main;


    # sendfile指令指定nginx是否调用sendfile函数(zero copy方式)来输出文件,对于普通应用,必须设为on。
    sendfile        on;
    
    # 此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用
    #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;

        # 定义web根路径
        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;
        }

        # 定义反向代理服务器数据服务器是lamp模型
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # 定义PHP为本机服务的模型
        # 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
        
        # 拒绝nginx DR目录及子目录下的.htaccess文件访问
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;


    # 定义虚拟主机配置基于ip、端口、域名方案
    # 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;
    #    }
    #}

}

查看进程

[root@003 ~]# lsof -i :80
# lsof命令 – 查看文件的进程信息
  -i <条件>	列出符合条件的进程

[root@003 ~]# ps -ef | grep nginx

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Nginx配置文件是用来配置Nginx服务器的行为和功能的文件配置文件通常位于Nginx安装目录下的`conf`文件夹中,主要有两个文件:`nginx.conf`和`sites-available/default`。其中,`nginx.conf`是主配置文件,而`sites-available/default`是默认的虚拟主机配置文件。 在Nginx配置文件中,可以设置一些全局的参数,如`worker_processes`用于指定Nginx的工作进程数,`events`用于配置事件模块,`http`用于配置HTTP模块等。此外,还可以使用`include`指令来引入其他配置文件,以便更好地组织和管理配置。 配置文件中的每个指令都有特定的作用,比如`pid`指令用于指定Nginx进程的PID存放路径,`location`指令用于URL地址匹配,可以实现对动态和静态网页的过滤处理,也可以用于实现反向代理和负载均衡等功能。 总之,Nginx配置文件是用来定义Nginx服务器的行为和功能的重要文件,通过对配置文件的修改和调整,可以实现对Nginx服务器的灵活配置和定制。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* [Nginx配置文件解析及功能演示](https://blog.csdn.net/pokes/article/details/121979187)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Nginx配置文件详解](https://blog.csdn.net/qq_41536778/article/details/104726671)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Stars.Sky

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值