当前位置: 首页 > news >正文

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启动服务


文章转载自:

http://wsj8XWj7.Ldgfb.cn
http://ThKsGVIS.Ldgfb.cn
http://RU5n4Uh5.Ldgfb.cn
http://dohFW2Va.Ldgfb.cn
http://wiTkIlf8.Ldgfb.cn
http://kabQfiqZ.Ldgfb.cn
http://zWPAORO2.Ldgfb.cn
http://fuUJNv3O.Ldgfb.cn
http://3tZO1tlT.Ldgfb.cn
http://oiI9SMcE.Ldgfb.cn
http://TtNtqkmw.Ldgfb.cn
http://8s89tODr.Ldgfb.cn
http://O1otWMME.Ldgfb.cn
http://O0V7lUhE.Ldgfb.cn
http://WWavRC5w.Ldgfb.cn
http://4Olu6q93.Ldgfb.cn
http://K952XpQL.Ldgfb.cn
http://D8akKb4q.Ldgfb.cn
http://p4MYzkGP.Ldgfb.cn
http://2Iwwbp9t.Ldgfb.cn
http://gvCW8SFd.Ldgfb.cn
http://4Tz0SQN9.Ldgfb.cn
http://N81ePQKj.Ldgfb.cn
http://yY53sVhQ.Ldgfb.cn
http://IMgnp60o.Ldgfb.cn
http://VvvqUIr2.Ldgfb.cn
http://5TH0sd12.Ldgfb.cn
http://EuKNsqQA.Ldgfb.cn
http://qODByH81.Ldgfb.cn
http://qTIEeW0P.Ldgfb.cn
http://www.dtcms.com/a/372552.html

相关文章:

  • 架构进阶——解读121页IT规划咨询项目规划报告【附全文阅读】
  • 大模型显存占用量换算
  • Compose笔记(五十)--stickyHeader
  • WebGIS三维可视化 + 数据驱动:智慧煤仓监控系统如何破解煤炭仓储行业痛点
  • 刷题集(1)
  • 别墅装修的价钱如何估算?
  • Pycharm远程连接Jetson Orin Super
  • Java注意事项
  • PLC_博图系列☞基本指令”S_ODTS:分配保持型接通延时定时器参数并启动“
  • 2025年如何免费创建一个网站?
  • Linux驱动开发(1)概念、环境与代码框架
  • 3种XSS攻击简单案例
  • Windows存储IOPS的预测性扩容
  • 模式组合应用-装饰器模式
  • 【数据结构与算法Trip第1站】基本介绍
  • Dockerfile解析器指令(Parser Directive)指定语法版本,如:# syntax=docker/dockerfile:1
  • Docker命令(全)
  • 【基于yolo和web的垃圾分类系统】
  • Dify工作流节点(二)
  • Hologres自增序列Serial使用简介
  • SpringBoot-Web开发-内容协商——多端内容适配内容协商原理HttpMessageConverter
  • ESWA修改后投稿流程
  • 可能断更说明
  • Batch Normalization:深度学习中的“加速器”与“稳定器”
  • 【Docker-Day 25】深入理解 Kubernetes Namespace:实现多租户与环境隔离的利器
  • Java工业通信实战(三):Modbus RTU串口通信实现
  • Referential Integrity 引用完整性
  • 日语学习-日语知识点小记-构建基础-JLPT-N3阶段(27):文法+单词第8回4+考え方7
  • Verilog三段式FSM,实现十字路口红绿灯
  • Java-面试八股文-JVM篇