nginx配置文件详解

我的系统环境是centos8.2,nginx版本是1.18.0。yum方式安装的nginx

nginx配置文件/etc/nginx/nginx.conf

#启动nginx工作进程的用户和组
user  nginx;
#启动的工作进程数
worker_processes  1;
#将nginx工作进程绑定到指定的CPU核心,默认nginx不进行进程绑定
#worker_cpu_affinity 0001 0010 0100 1000

#nginx错误日志配置
#warn表示错误级别,除了warn还设有debug、info、notice、warn、error、crit、alert、emerg
error_log  /var/log/nginx/error.log warn;
#pid文件保存路径
pid        /var/run/nginx.pid;

#工作进程的优先级 -20~19
work_priority 0;
#工作进程最大打开文件数
work_rlimit_nofile 65536;

#前台运行nginx用于测试,docker等环境,默认为on
daemon off|on;
#是否开启nginx的master-woker工作模式,关闭后 nginx就不会fork出worker子进程来处理请求,而是以master进程自身来处理请求
master_process off|on;

#events设置块
events {
    #设置单个nginx工作进程可以接受的最大并发连接数据;
    ##在nginx作为http服务器的时候,最大连接数为worker_processes * worker_connctions;
    ##在nginx作为反向代理服务器的时候,最大连接数为worker_processes * worker_connections / 2
    worker_connections  1024;
    #使用epoll事件驱动,nginx支持众多的事件驱动,比如select、poll、epoll,只能设置在events模块中设置
    use epoll;
    #优化同一时刻只有一个请求而避免多个睡眠进程被唤醒的设置,on为防止被同时唤醒默认为off,全部唤醒的过程也成为"惊群",因此nginx刚安装完以后要进行适当的优化
    accept_mutex on;
    #nginx服务器的每个工作进程可以同时接受多个新的网络连接,但是需要在配置文件中配置,此指令默认为关闭,即默认为一个工作进程只能一次接受一个新的网络连接,打开后几个同时接受多个
    multi_accept on;

}

#http设置块
http {
    #导入支持的文件类型
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    #指定是否使用sendfile系统调用来传输文件
    sendfile        on;
    #在开启了sendfile的情况下,合并请求后统一发送给客户端
    #tcp_nopush     on;
    #在开启了keepalived模式下的连接是否启用TCP_NODELAY选项,当为off时,延迟0.2s发送,默认为on,不延迟发送,立即发送用户相应报文
    #tcp_nodelay off;
    #设置会话保持时间,单位是秒
    keepalive_timeout  65;
    #开启文件压缩
    #gzip  on;

    #其他配置文件
    include /etc/nginx/conf.d/*.conf;
}

服务模块

server {
    #设置监听关口
    listen       80;
    #设置server name,可以以空格隔开写多个,支持正则表达式
    server_name  localhost;
    #指定网站目录
    root         /var/www/;
    #指定默认网页文件,此指令由ngx_http_index_module模块提供
    index  index.html index.htm;

    #设置编码格式,默认是俄语格式,可以改为utf-8
    #charset utf-8;
    #设备访问日志
    #access_log  logs/host.access.log  main;
    #/404.html;
    #error_page  404
    #/50x.html
    #redirect server error pages to the static page
    error_page 500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    #以http的方式转发php请求到指定web服务器
    #location ~ \.php$ {
         #proxy_pass   http://127.0.0.1;
    #}

    #以fastcgi的方式转发php请求到php处理
    #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;
    #}

    #拒绝web形式访问指定文件,如很多的网站都是通过.htaccess文件来改变自己的重定向等功能。
    #location ~ /\.ht {
    #    deny  all;
    #}

    location ~ \.php(/|$) {
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        #使其支持thinkphp的pathinfo模式
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
    }
}
#自定义虚拟server
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    #https服务器配置
    #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;
    #    }
    #}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值