nginx学习笔记--nginx配置文件详细说明

前言 :nginx 的配置文件是学习nginx的过程中组重要的一环。
       配置文件的路径: 在nginx 的安装目录下 conf/nginx.conf

配置文件的组织结构

在这里插入图片描述
main: 代表整个配置文件
http:处理web请求

  • server: 代表一个web服务器
    • location: web服务器要处理的一个指令

mail:处理邮件相关的协议

基础配置

#配置 worker 进程运行用户 nobody 也是一个 linux 用户,一般用于启动程序,没有密码                                                                         
#user  nobody;  worker 进程属于谁,默认属于nobody

#配置工作进程数目,根据硬件调整,通常等于cpu 数量或者 2 倍于cpu 数量
worker_processes  1; #worker 进程的个数
#worker_rlimit_core 1000m;
#working_directory /usr/local/nginx/logs;

#配置全局错误日志即类型 [debug | info | notice | warn | error | crit ], 默认 error  从左往右 兼容
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid; # pid 文件的生成目录

events 配置

# use epoll;    可以使用在内核版本2.6
#配置工作模式和连接数
events{
    #use epoll
    worker_connections  1024; #epoll_create 的一个参数,最大连接数,理论值 worker 进程的连接上限
    # nginx 支持的总连接数 work进程 * worker_connections
}

http配置

#配置http 服务器,利用它的反向代理功能提供负载均衡支持
http {
    #配置 nginx 支持那些多媒体类型,可以子啊conf/mime.types 查看那些多媒体类型
    include       mime.types; #mime.types 是一个文件
    #默认文件类型 流类型,可以理解为支持任意类型
    default_type  application/octet-stream;
 #   ssl_session_cache    shared:SSL:10m;

#配置日志的格式
# main 为日志格式的 名字
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 日志记录到 后面的 路径中, 采用 main 格式
    access_log  logs/access.log  main;

    sendfile        on; #开启高效文件传输模式
    #tcp_nopush     on; #防止网络阻塞

    #keepalive_timeout  0;
    keepalive_timeout  65;  #连接超时的事件 单位 s

    #gzip  on; 开启gzip 压缩输出


server 配置


#配置虚拟主机

    server {
        listen       8080; #server 监听的端口
        server_name  localhost; #对应的是域名, 不能写IP  好像可以写ip,有待商榷 配置服务名

        #charset koi8-r; #配置字符集 默认 utf-8

        #access_log  logs/host.access.log  main;  #配置本虚拟主机的访问日志

	# / 代表资源更目录
	# html 是一个目录  放置静态网络
 #      location / {
  #     	alias html/;
   #    }


       #处理一个指令
       #url : http://192.168.1.3/test
       #location /test{
       #      配置fastcgi 模块
       #      数据要发送的地方
      #       fastcgi_pass 127.0.0.1:9001;
       #      包含一个配置文件
      #       include fastcgi.conf;
       #
      # }
       
       #默认
       #默认的匹配斜杠 / 的请求,当访问路径中有斜杠 /,会被 location 匹配到并进行处理
       location / {
       #root 是配置服务器的默认网站根目录位置,默认为 nginx 安装主目录 下的 html 目录
       root   html/; #root  本地磁盘的根路径
	   autoindex on;
	   set $limit_rate 1k; #限制nginx 向游览器 发送数据的速度 为1k

       # 从index.html 开始找, 如果找不到 就开始找第二个
	   #配置首页文件的名称
       #index  index.html index.htm;
       }
	
	#为了方便下,直接冲storage 上下载
	location /group1/M00{
		#root /home/tt/fastDFS/storage/data;
		ngx_fastdfs_module;
	}

	#配置 404 页面
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        
	# 配置50x 错误页面
        error_page   500 502 503 504  /50x.html;

	#精确匹配
        location = /50x.html {
           root   html;
       }

猜你喜欢

转载自blog.csdn.net/qq_43701555/article/details/107661775