nginx.conf核心配置文件

1.设置worker进程的用户,linux中的用户,涉及到Nginx操作目录或文件的一些权限,认为nobody

在这里插入图片描述

	user root;

2.worker进程数,设置数与cpu相同或比cpu一个

	worker_processes 1;

3.Nginx日志级别 | debug | info| notice | warn | error | crit | alert | emerg |,错误级别从左到右越来越大

	error_log logs/error.log notice;
	error_log logs/error.log info;

4.设置Nginx进程pid

	pid logs/Nginx.pid

5.设置工作模式

	events{
		#认使用epoll
		use epoll;
		#每个worker允许连接的客户端最大数
		worker_connections 1024;
	}

6.include引入外部配置,提高可读性,可以避免配置文件过大

	include		mime.types;

7.设置日志输出格式,main为定义的格式名称,access_log可以直接使用这个变量

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 log/access.log main;					

参数解析

参数名参数意义
$remote_addr客户端ip
$remote_user远程客户端用户名,一般为‘-’
$time_local时间和时区
$request请求的url以及method
$status响应状态码
$body_bytes_sent响应客户端内容字节数
$http_referer记录用户从哪个连接跳过来的
$http_user_agent用户所使用的代理
$http_x_forwarded_for通过代理服务器来记录客户端ip

8.sendfile使用高效文件传输,提高传输性能。启用后才能使用tcp_nopush,tcp_nopush是指当数据表积累一定大小后才发送,提高了效率

	sendfile		on;
	tcp_nopush		on;

9.keepalive_timeout 设置客户端与服务器端请求的超时时间,保证客户端多次请求的时候不会重复建立新的连接,节约资源损耗。

	keepalive_timeout 65;
	# keepalive_timeout 0;

10. gzip启用压缩,html/js/css压缩后传输会更快

	gzip	on;

11.server可以在http指令块中设置多个虚拟主机

  • listen 监听端口
  • server_name localhost ip或域名
  • location 请求路由映射,匹配拦截
  • root 请求位置
  • index 首页设置
werver{
        location / {
            root   myhtml;
            index  myindex.html index.htm;
        }

}

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...