ngnix.conf的配置结构

1.ngnix.conf的配置结构

ngnix.conf结构图

2.部分配置文件说明

#worker进程可操作的用户
#user  nobody;
#设置worker的个数
worker_processes  1;

#错误日志
#error_log  logs/error.log;
#日志级别 debug info notice warn error crit
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#nginx的进程号
#pid        logs/nginx.pid;

#事件处理
events {
	#操作模式,默认使用epoll(linux系统使用)
	use epoll;
	#设置每个worker的客户端最大连接数
    worker_connections  1024;
}

#相关网络传输模块
http {
	#导入的外部指令(外部文件)mime.types在conf目录下
    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"';
	#http请求的日志文件
    #access_log  logs/access.log  main;
	#打开文件传输
    sendfile        on;
	#与sendfile一起使用,但数据包累计到一定程度以后再去发送
    #tcp_nopush     on;

    #keepalive_timeout  0;
	#http保持连接的状态超时时间(单位秒)
    keepalive_timeout  65;
	
	#开启内容传输压缩
    #gzip  on;
        #限制最小压缩,小于1字节的文件不会压缩
    #gzip_min_length 1
        #定义压缩的级别(文件越大,压缩越多,但是cpu占用越高)
     #gzip_comp_level 3
       #定义压缩文件的类型
      gzip_type gzip_types text/plain application/javascript application/x-javascript text/css applicatio n/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/ json;|



	#服务器配置
    server {
		#监听的端口
        listen       80;
		#监听的域名
        server_name  localhost;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;
		# /匹配的请求地址
        location / {
			#影射的文件夹,html表示conf的同级目录的html文件夹
            root   html;
			#指定默认的首页
            index  index.html index.htm;
        }
        #默认的配置
         location / {
			#影射的文件夹,html表示conf的同级目录的html文件夹
            root   html;
			#指定默认的首页
            index  index.html index.htm;
        }
        #当用户请求 /test,nginx会自动拼接到/home后面,即访问/home/test路径
        location /test {
			#影射的文件夹,html表示conf的同级目录的html文件夹
            root   /home;

        }
      #alias来设置别名,当用户访问/static,nginx影射到 /home/static路径中
        location /static {
			#影射的文件夹,html表示conf的同级目录的html文件夹
            alias   /home/static;

        }

        #error_page  404              /404.html;

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



}

3.配置重新加载才生效

进入sbin目录,输入如下路径

./nginx -s reload
原文地址:https://www.cnblogs.com/xiaodou00/p/13470484.html