ITPub博客

首页 > IT职业 > IT生活 > nginx配置文件自己的理解

nginx配置文件自己的理解

IT生活 作者:adder 时间:2021-09-09 10:06:03 0 删除 编辑

公司开发和自己网站都在用nginx,但是对它的配置还是一知半解,今天特意整理一下,该版本是nginx1.10.2且并非默认nginx默认配置(有改动),如有需要请直接去官方下载。

#运行用户,默认即是nginx,可以不进行设置
#user   nobody;

#Nginx进程,一般设置为和CPU核数一样,或者auto
worker_processes   2;

#错误日志存放目录 
#error_log   logs/error.log;
#error_log   logs/error.log   notice;
#error_log   logs/error.log   info;

#进程pid存放位置 
#pid      logs/nginx.pid;
 
 
events {
	worker_connections   1024; # 单个后台进程的最大并发数
}
 
 
http {
	include   mime.types;		#文件扩展名与类型映射表
	include   proxy.conf;		#默认文件类型
	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   logs/access.log   main;		#nginx访问日志存放位置
	 
	sendfile      on;		#开启高效传输模式
	
	client_max_body_size 500M;		#设置请求报文大小
 	client_body_buffer_size 512k;		#设置缓冲区

	#tcp_nopush    on;		#减少网络报文段的数量
	 
	#keepalive_timeout   0;
	keepalive_timeout   65;		#保持连接的时间,也叫超时时间
	 
	#gzip   on;		#开启gzip压缩
	 
	 
	# SSL证书配置 
	# HTTPS server
	#
	#server {
	# listen   443;
	# server_name   localhost;
	 
	# ssl           on;
	# ssl_certificate   cert.pem;
	# ssl_certificate_key   cert.key;
	 
	# ssl_session_timeout   5m;
	 
	# ssl_protocols   SSLv2 SSLv3 TLSv1;
	# ssl_ciphers   ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
	# ssl_prefer_server_ciphers on;
	 
	# location / {
	#      root html;		#服务默认启动目录
	#      index   index.html index.htm;		#默认访问文件
	# }
	#}


	server{
		listen 80;		#配置监听端口
	    server_name   nginx.org;		#配置域名
		root html;

		#匹配访问根目录
		location / {
			index index.html index.htm;
			proxy_pass http://192.168.2.2:8888;  #配置反向代理
		}


		#匹配规则
		location ~  .*.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|woff|ttf|json)$ {
        root html/demo/static;
		}
	}
}

这里只是整理与说明,不能做到开箱即用,请勿直接用于生产环境。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1595/viewspace-2816333/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    110
  • 访问量
    724