nginx配置文件详解

本文将深入解析Nginx配置文件nginx.conf,主要关注全局配置和http模块。Nginx作为一款功能强大的服务器,其配置复杂且深奥,但了解核心配置对于优化服务器性能至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx配置文件位于nginx目录下的conf文件夹下,为nginx.conf,下面简单介绍下配置文件中各项的含义,一入nginx深似海,功能非常强大,同时也非常复杂。

全局配置:

user nobody; #运行用户

worker_processes 1; #表示工作进程的数量,通常设置成和CPU的数量相等

全局错误日志以及pid文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
Events模块:

events {
    worker_connections  1024; #单个后台worker process进程的最大并发连接数
}

http模块:

http {
    include       mime.types; #设定mime类型,类型由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; #指令指定nginx是否调用sendfile函数来输出文件
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65; #连接超时时间
    #gzip  on; #开启gzip压缩
    autoindex on; #设置显示项目目录 
    
 #设定虚拟主机配置
 server {
     listen       80; #监听80端口
     server_name  demo.shop.cn; #设置访问域名
     root html; #定义服务器的默认项目根目录
     #charset koi8-r;

     #access_log  logs/host.access.log  main; #设定本虚拟主机的默认访问日志
  

        #默认请求
        location / {
            root   html;
            index  index.php 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

        #PHP脚本请求全部转发到FastCGI处理,使用FastCGI默认配置
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$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;
        #}
    }










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值