文件结构
配置文件
#运行用户,默认即是nobody,可不设置#user nobody;#nginx进程,一般设置为和cpu核数一样 ,auto 自动检测worker_processes 1;#错误日志存放目录 #error_log 级别分为 debug, info, notice, warn, error, crit 默认为error#crit 记录的日志最少,而debug记录的日志最多。#如果nginx遇到一些问题,比如502比较频繁出现,但是看默认的error_log并没有看到有意义的信息,#那么就可以调一下错误日志的级别,当你调成error级别时,错误日志记录的内容会更加丰富。#这些值是互斥的,也就是说只能取其中之一,如果像下面同时配置多个日志级别会报错#error_log logs/error.log;#error_log logs/error.log error;#error_log logs/error.log notice;#error_log logs/error.log info;#进程pid存放位置#pid logs/nginx.pid;#单个后台worker process进程的最大并发链接数 最大设置 worker_connections*worker_processes =ulimit -n open filesevents { worker_connections 1024;}http { #主模块命令,对配置文件所包含文件的设定,减少主配置文件的复杂度,相当于把部分设置放在别的地方, #然后在包含进来,保持主配置文件的简洁 include mime.types; #默认文件类型,当文件类型未定义时候就使用这类设置的 default_type application/octet-stream; #$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址; #$remote_user:用来记录客户端用户名称; #$time_local: 用来记录访问时间与时区; #$request: 用来记录请求的url与http协议; #$status: 用来记录请求状态;成功是200, #$body_bytes_sent :记录发送给客户端文件主体内容大小; #$http_referer:用来记录从那个页面链接访问过来的; #$http_user_agent:记录客户浏览器的相关信息; #通常web服务器放在反向代理的后面,这样就不能获取到客户的IP地址了,通过$remote_add拿到的IP地址是反向代理服务器的iP地址。反向代理服务器在转发请求的http头信息中,可以增加x_forwarded_for信息,用以记录原有客户端的IP地址和原来客户端的请求的服务器地址。 #日志格式 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 logs/access.log main; #开启高效文件传输模式(zero copy 方式),避免内核缓冲区数据和用户缓冲区数据之间的拷贝 sendfile on; #开启TCP_NOPUSH套接字(sendfile开启时有用) #tcp_nopush on; #客户端连接超时时间 #keepalive_timeout 0; keepalive_timeout 65; #用于从 upstream 读取返回数据时 proxy_read_timeout 1800s; #设置是否开启gzip模块 #gzip on; #开启目录 #autoindex on; server { # 虚拟主机的服务端口 listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # "50x.html" 是个文件名 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # fastcgi_pass 只适用于php # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
更详细内容:
https://www.w3cschool.cn/nginx/nginx-d1aw28wa.html