nginx配置文件选项详解
2022年5月31日大约 1 分钟约 365 字
默认配置文件内容
nginx.conf默认配置文件内容
# nginx服务使用的用户
user nginx;
# 工作进程数,一般和cpu核心数保持一致
worker_processes 1;
# nginx的错误日志路径
error_log /var/log/nginx/error.log warn;
# nginx服务启动的pid存放路径
pid /var/run/nginx.pid;
# 事件模块,配置内核模型
events {
worker_connections 1024; #每个进程允许最大连接数,一般调到10000左右就行
}
# http协议中间件配置
http {
include /etc/nginx/mime.types; # content-type配置
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;
#tcp_nopush on;
# 设置客户端超时时间
keepalive_timeout 65;
#gzip on;
# 最后会读这些配置
include /etc/nginx/conf.d/*.conf;
}
conf.d/default.conf默认配置
server { # 虚拟主机
listen 80; # 监听端口
server_name dongfe.com; # 域名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / { # 域名根路径(首页)或其子路径的文件位置
root /usr/share/nginx/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 404 /50x.html; # 错误页面
location = /50x.html { # /50x.html文件的位置
root /usr/share/nginx/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
#
#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
#
#location ~ /\.ht {
# deny all;
#}
}