nginx基础配置语法

版权声明:如果您觉得此文有用或对您有帮助,请不吝点个赞或留个言,哈哈! https://blog.csdn.net/fanrenxiang/article/details/83307374

上篇:nginx初识与nginx安装https://blog.csdn.net/fanrenxiang/article/details/83306818

首先打开nginx配置文件,cat /etc/nginx/nginx.conf,查看nginx默认的配置文件如下:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
user nginx的使用用户,不建议设置为root
worker_processes nginx的工作进程数,建议设置为系统CPU数即可
error_log nginx的错误日志
pid nginx启动时的进程id
worker_connnections 每个进程的最大并发连接数,1024是默认,可以根据需求调大,我们项目中调节为20480
include mime.types 设定mime类型
default_type ~
log_format nginx日志输出格式
access_log nginx日志存放路径
sendfile 系统调用,建议开启,nginx的优势之一
tcp_nopush 数据包达到最大时一次性发送,与tcp_nodelay互斥,只有在sendfile开启时才生效
keepalive_timeout 请求会话超时时间,默认60s
gzip 压缩请求的响应信息,默认关闭
include file 生效的nginx配置信息,默认在/etc/nginx/conf.d/目录下以.conf结尾的,一般会对nginx配置文件分类管理,便于管理

nginx的配置点很多,建议按照模块来看,在官网上都有详细的说明。http://nginx.org/en/docs/

猜你喜欢

转载自blog.csdn.net/fanrenxiang/article/details/83307374