nginx主配置文件
时间: 2023-06-29 14:06:53 浏览: 51
nginx 的主配置文件是 `nginx.conf`,通常位于 `/etc/nginx/` 目录下。在该文件中,可以配置全局的 nginx 选项和虚拟主机。
以下是一个简单的 nginx 主配置文件示例:
```
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
```
其中,`user` 指定 nginx 运行的用户,`worker_processes` 指定工作进程数,`error_log` 指定错误日志文件路径,`pid` 指定进程 ID 文件路径,`events` 指定事件模块的配置,`http` 指定 HTTP 模块的配置,包括 MIME 类型、访问日志、TCP 相关参数、压缩等。`include` 指令可用于包含其他配置文件,使主配置文件更加简洁易读。