Nginx主配置文件

一,Nginx基本介绍

1,nginx概念

Nginx 是一款轻量级、高性能的服务器软件,核心能力是 "处理网络请求",被广泛用于网站、App 的后端架构中。

Nginx 就像一个 "高效的网络交通指挥官",核心价值是用最少的资源,处理最多的请求,让整个系统又快又稳。无论是小网站还是像淘宝、抖音这样的巨头,几乎都离不开它 ------ 它是现代互联网架构的 "基础设施" 之一。

(与浏览器为两端

2,nginx优势

  1. 高并发:事件驱动模型 + 单线程 Worker 进程,单台服务器可支撑数万并发连接;
  2. 高可靠:Master-Worker 进程隔离,Worker 故障自动重启,服务可用性高;
  3. 高性能:非阻塞 I/O 减少等待,内存占用低(通常几 MB 到几十 MB);
  4. 高扩展:模块化设计支持按需扩展,第三方模块丰富;
  5. 易运维:支持平滑重载配置、版本升级,运维操作不中断服务。

二,nginx主配置文件

/usr/local/nginx/conf/nginx.conf

root@web1 conf\]# cat nginx.conf ##### 1,基本信息 #user nobody; 使用的nginx账号 worker_processes 1; 工作进程数量(看CPU核数量 #error_log logs/error.log; 错误日志配置 #error_log logs/error.log notice; notice级别 #error_log logs/error.log info; info级别 #pid logs/nginx.pid; pid文件路径 events { }事件模块 events { worker_connections 1024; 最大并发数 1024 } ##### 2,http模块 http { }模块,处理HTTP协议 http { include mime.types; 引入MINE类型映射文件 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; 访问日志路径 sendfile on; 开启 sendfile 机制(零拷贝技术),加速静态文件(如图片、HTML)的传输效率 #tcp_nopush on; 网络传输次数 #keepalive_timeout 0; 关闭长连接 keepalive_timeout 65; 65秒长连接 #gzip on; GZIP压缩 server{ } 模块,在http模块 虚拟主机配置 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; 404错误跳转页面 # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; 服务错误(500/501/502/503/504 location = /50x.html { 精确·匹配 /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; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # PHP 相关配置,对接PHP服务 #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 # 禁止访问 .htaccess 文件(默认注释,若与 Apache 共用目录时启用) #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; # } #} ##### 3,https模块 HTTPS 服务示例 # HTTPS server # #server { # listen 443 ssl; 监听 443 端口 (HTTPS默认端口 并启用SSL # server_name localhost; # ssl_certificate cert.pem; SSL 证书文件(公钥 # ssl_certificate_key cert.key; SSL 私钥文件 # 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; # } #} **}** #### 三,nginx的目录结构 [root@dns-nfs conf]# cd /usr/local/nginx8 [root@dns-nfs nginx8]# ls client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp [root@dns-nfs nginx8]# ##### 1,`client_body_temp`:客户端请求体临时存储目录 ##### 2,conf:核心目录 root@load2 conf]# ls fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default fastcgi_params koi-win nginx.conf scgi_params.default win-utf [root@load2 conf]# nginx.conf Nginx 主配置文件 mine.types MIME 类型映射文件 koi-utf win 字符集转换映射表 (.default是默认备份文件 ##### 3,html 默认静态资源根目录 (快速部署静态服务) [root@load2 nginx8]# cd html [root@load2 html]# ls 50x.html index.html [root@load2 html]# index.html nginx 默认欢迎页,内容为 "Welcome to nginx!",是 Nginx 安装完成后,访问 `http://服务器IP` 或 `http://localhost` 时默认返回的页面; 50x.html nginx默认错误页面 (可以在nginx主配置文件server模块修改 server { listen 80; server_name www.my-static.com; # 自定义域名 root /var/www/my-static; # 自定义静态资源目录(需手动创建) index index.html index.htm; # 默认首页优先级 } ##### 4,logs 日志核心目录 [root@load2 logs]# ls access.log error.log nginx.pid [root@load2 logs]# access.log 访问日志 error.log 错误日志 nginx.pid 进程 ID 文件(管理 Nginx 服务) pi进程标识符 ##### 5,sbin [root@load2 nginx8]# cd sbin [root@load2 sbin]# ls nginx [root@load2 sbin]# 编译安装的 .nginx启动服务

相关推荐
tg-zm88999610 小时前
2025返利商城源码/挂机自动收益可二开多语言/自定义返利比例/三级分销理财商城
java·mysql·php·laravel·1024程序员节
X***C86210 小时前
SpringBoot:几种常用的接口日期格式化方法
java·spring boot·后端
j***294810 小时前
IPV6公网暴露下的OPENWRT防火墙安全设置(只允许访问局域网中指定服务器指定端口其余拒绝)
服务器·安全·php
ao_lang10 小时前
数据链路层
linux·服务器·网络
前端达人10 小时前
你的App消息推送为什么石沉大海?看Service Worker源码我终于懂了
java·开发语言
小光学长10 小时前
基于ssm的宠物交易系统的设计与实现850mb48h(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·前端·数据库
编程大师哥10 小时前
vxe-table 透视表分组汇总及排序基础配置
java
额呃呃10 小时前
零拷贝I/O的核心概念
服务器·php·apache
8***848211 小时前
spring security 超详细使用教程(接入springboot、前后端分离)
java·spring boot·spring
9***J62811 小时前
Spring Boot项目集成Redisson 原始依赖与 Spring Boot Starter 的流程
java·spring boot·后端