Nginx 主配置文件详解

# 全局参数设置
user nginx; #指定用户
worker_processes 4; #设置nginx启动进程的数量,一般设置成与逻辑cpu数量相同
error_log logs/error.log; #指定错误日志
worker_rlimit_nofile 10240; #设置一个nginx进程能打开的最大文件数
pid /var/run/nginx.pid;
events {
worker_connections 1024; #设置一个进程的最大并发连接数
}
# http 服务相关设置
http {
include 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; #是否调用sendfile函数输出文件,一般设置为on,若nginx是用来进行磁盘IO负载应用
时,可以设置为off,降低系统负载
gzip on; #是否开启gzip压缩,将注释去掉开启
keepalive_timeout 65; #设置长连接的超时时间
# 虚拟服务器的相关设置
server {
listen 80; #设置监听的端口
server_name localhost; #设置绑定的主机名、域名或ip地址
# charset koi8-r; # 设置编码字符
charset utf-8;
location / {
root /var/www/nginx; #设置服务器默认网站的根目录位置,需要手动创建
index index.html index.htm; #设置默认打开的文档
}
error_page 500 502 503 504 /50x.html; #设置错误信息返回页面
location = /50x.html {
root html; #这里的绝对位置是/usr/local/nginx/html
}
}
}

**

nginx.conf的组成 : nginx.conf一共由三部分组成,分别为:全局块、events块、http块。在http块中又包含http全局块、多个server块。每个server块中又包含server全局块以及多个 location块。在统一配置块中嵌套的配置快,各个之间不存在次序关系。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值