Nginx详细入门-Nginx常用配置以及基本功能一

时间:2025-04-09 12:00:51
user nginx; worker_processes auto; #worker_processes 1; 默认为1,表示开启一个业务进程 error_log /var/log/nginx/ notice;#制定日志路径,级别:debug|info|notice|warn|error|crit|alert|emerg pid /var/run/; #指定nginx进程运行文件存放地址 events { worker_connections 1024; # 单个业务进程可接受最大连接数,默认为512 } http { include /etc/nginx/; #文件扩展名与文件类型映射表 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 /var/log/nginx/ main; sendfile on;# 使用linux的 sendfile(socket, file, len) 高效网络传输,也就是数据0拷贝。 #tcp_nopush on; keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。 # 第一个Server区块开始,表示一个独立的虚拟主机站点 server { keepalive_requests 120; #单连接请求上限次数。 listen 8081; #监听端口,监听地址默认就是127.0.0.1 location /login { # 请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。 proxy_pass http://127.0.0.1:8081/; #请求转发到哪 } location / { # 请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。 root /usr/share/nginx/html/dist; #请求到达后的文件根目录 index ; #设置默认页 fastcgi_buffers 256 128k; chunked_transfer_encoding off; } } # include /etc/nginx//*.conf; }