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

nginx的配置文件概述及简单demo(二)

默认配置文件

当安装完nginx后,它的目录下通常有默认的配置文件


#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;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;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  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#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;#}# 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;#    }#}}

可以看到主要分为3个部分

  • 全局块
    从开头到events块之间的内容,被称为全局块,从配置文件开始到 events 块之间的内容,主要会设置一些影响 nginx 服务整体运行的配指,主要包括配置运行 Nginx 服务器的用户(组)、允许生成的 worker process ,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等。

这里部分是全局块的内容,这里面除了注释,只有 “worker_processes 1;”,这样一条属性配置

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;

这是 Nginx 服务器并发处理服务的关健配置,worker_processes 值越大,可以支持的并发处理量也越多,但是受到硬件、软件等设备的制约

  • event块
events {worker_connections  1024;
}

events 块涉及的指今主要影响 Nginx 服务与用户的网络连接,常用的设置包括是否开启对多 work process下的网络连接进行序列化,是否允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 word process 可以同时支持的最大连接数等。
上述例子就表示每个 work process 支持的最大连接数为 1024.这部分的配置对 Nginx 的性能影响较大,在实际中应该灵活

  • http块
    这算是 Nginx 服务器配置中最频察的部分,代理、缓存和志定义等绝大多数功能和第三方模块的配置都在这里
    需要注意的是:http 块也可以包括 http 全局块、server 块
http {include       mime.types;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;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  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#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;#}# 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;#    }#}}

http块配置详解

http 块也可以包括 http 全局块、server 块

http全局块

http 全局块配置的指>包括文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等

    include       mime.types;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;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;

server块

这块和虚拟主机有密切关系,虚拟主机从用户角度看,和一台独立的硬件主机是完全一样的,该技术的产生是为了节省互联网服务器硬件成本。每个 http 块可以包括多个 server 块,而每个 server 块就相当于一个虚拟主机。而每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块。

 server {listen       80;server_name  localhost;location / {root   html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}

而实际上server块也可以接着细分下去,每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块。
全局server块的内容

listen       80;
server_name  localhost;
error_page   500 502 503 504  /50x.html;

locaton 块内容

location / {root   html;index  index.html index.htm;}location = /50x.html {root   html;}

我们实际上要配置的内容都在http块中,给两个简单地例子

nginx简单demo

demo1

访问nginx转到tomcat页面,修改nginx配置,修改server_name,以及location / 模块的转发路径

worker_processes  1;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  121.4.170.108;location / {proxy_pass  http://127.0.0.1:8080;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}}

这里我们监听了80端口,然后server_name是主机名或者ip,转发路径是我们tomcat的地址

demo2

部署多个tomcat,使用nginx做反向代理,部署在同一个服务器,根据路径转换到不同的服务器 ,127.0.0.1即代表本地,proxy_pass后面的地址代表我们转发的路径

worker_processes  1;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  121.4.170.108;# 在页面输入121.4.170.108  会默认跳转到tomcat的页面location / {proxy_pass  http://127.0.0.1:8080;}# 第一个tomcat代理location ~ /a/ {proxy_pass   http://127.0.0.1:8080;}# 第一个tomcat的代理location ~ /b/ {proxy_pass   http://127.0.0.1:8081;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}
}

相关文章:

nginx的配置文件概述及简单demo(二)

默认配置文件 当安装完nginx后,它的目录下通常有默认的配置文件 #user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connection…...

Apollo Planning2.0决策规划算法代码详细解析 (2): vscode gdb单步调试环境搭建

前言: apollo planning2.0 在新版本中在降低学习和二次开发成本上进行了一些重要的优化,重要的优化有接口优化、task插件化、配置参数改造等。 GNU symbolic debugger,简称「GDB 调试器」,是 Linux 平台下最常用的一款程序调试器。GDB 编译器通常以 gdb 命令的形式在终端…...

flex 布局:元素/文字靠右

前言 略 使用flex的justify-content属性控制元素的摆放位置 靠右 <view class"more">展开更多<text class"iconfont20231007 icon-zhankai"></text></view>.more {display: flex;flex-direction: row;color: #636363;justify-co…...

java基础-第1章-走进java世界

一、计算机基础知识 常用的DOS命令 二、计算机语言介绍 三、Java语言概述 四、Java环境的搭建 JDK安装图解 环境变量的配置 配置环境变量意义 配置环境变量步骤 五、第一个Java程序 编写Java源程序 编译Java源文件 运行Java程序 六、Java语言运行机制 核心机制—Java虚拟机 核…...

jvm 堆内存 栈内存 大小设置

4种方式配置不同作用域的jvm的堆栈内存。 1、Eclise 中设置jvm内存: 改动eclipse的配置文件,对全部project都起作用 改动eclipse根文件夹下的eclipse.ini文件 -vmargs //虚拟机设置 -Xms40m //初始内存 -Xmx256m //最大内存 -Xmn16m //最小内存 -XX:PermSize=128M //非堆内…...

免杀对抗-反沙盒+反调试

反VT-沙盒检测-Go&Python 介绍&#xff1a; 近年来&#xff0c;各类恶意软件层出不穷&#xff0c;反病毒软件也更新了各种检测方案以提高检率。 其中比较有效的方案是动态沙箱检测技术&#xff0c;即通过在沙箱中运行程序并观察程序行为来判断程序是否为恶意程序。简单来说…...

QTimer类的使用方法

本文介绍QTimer类的使用方法。 1.单次触发 在某些情况下&#xff0c;定时器只运行一次&#xff0c;可使用单次触发方式。 QTimer *timer new QTimer(this); connect(timer, &QTimer::timeout, this, &MainWindow::timeout); timer->setSingleShot(true); timer-…...

(三)行为模式:9、空对象模式(Null Object Pattern)(C++示例)

目录 1、空对象模式&#xff08;Null Object Pattern&#xff09;含义 2、空对象模式的主要涉及以下几个角色 3、空对象模式的应用场景 4、空对象模式的优缺点 &#xff08;1&#xff09;优点 &#xff08;2&#xff09;缺点 5、C实现空对象模式的实例 1、空对象模式&am…...

Django实战项目-学习任务系统-用户登录

第一步&#xff1a;先创建一个Django应用程序框架代码 1&#xff0c;先创建一个Django项目 django-admin startproject mysite将创建一个目录&#xff0c;其布局如下&#xff1a;mysite/manage.pymysite/__init__.pysettings.pyurls.pyasgi.pywsgi.py 2&#xff0c;再创建一个…...

【动手学深度学习-Pytorch版】Transformer代码总结

本文是纯纯的撸代码讲解&#xff0c;没有任何Transformer的基础内容~ 是从0榨干Transformer代码系列&#xff0c;借用的是李沐老师上课时讲解的代码。 本文是根据每个模块的实现过程来进行讲解的。如果您想获取关于Transformer具体的实现细节&#xff08;不含代码&#xff09;可…...

做外贸独立站选Shopify还是WordPress?

现在确实会有很多新人想做独立站&#xff0c;毕竟跨境电商平台内卷严重&#xff0c;平台规则限制不断升级&#xff0c;脱离平台“绑架”布局独立站&#xff0c;才能获得更多流量、订单、塑造品牌价值。然而&#xff0c;在选择建立外贸独立站的过程中&#xff0c;选择适合的建站…...

echarts的bug,在series里写tooltip,不起作用,要在全局先写tooltip:{}才起作用,如果在series里写的不起作用就写到全局里

echarts的bug&#xff0c;在series里写tooltip&#xff0c;不起作用&#xff0c;要在全局先写tooltip&#xff1a;{show:true}才起作用&#xff0c;如果在series里写的不起作用就写到全局里 series里写tooltip不起作用&#xff0c;鼠标悬浮在echarts图表上时不显示提示 你需要…...

jmeter分布式压测

一、什么是压力测试&#xff1f; 压力测试&#xff08;Stress Test&#xff09;&#xff0c;也称为强度测试、负载测试&#xff0c;属于性能测试的范畴。 压力测试是模拟实际应用的软硬件环境及用户使用过程的系统负荷&#xff0c;长时间或超大负荷地运行被测软件系统&#xff…...

consulmanage部署

一、部署consul 使用yum方式部署consul yum install -y yum-utils yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo yum -y install consul 执行以下命令获取uuid密钥并记录下来 uuidgen 编辑consul配置文件 vi /etc/consul.d/consul.h…...

大数据软件项目的验收流程

大数据软件项目的验收流程是确保项目交付符合预期需求和质量标准的关键步骤。以下是一般的大数据软件项目验收流程&#xff0c;希望对大家有所帮助。北京木奇移动技术有限公司&#xff0c;专业的软件外包开发公司&#xff0c;欢迎交流合作。 1.项目验收计划制定&#xff1a; 在…...

《第一行代码Andorid》阅读笔记-第一章

这篇文章是我自己的《第一行代码Andorid》的阅读笔记&#xff0c;虽然大量参考了别人已经写好的一些笔记和代码但是也有自己的提炼和新的问题在里面&#xff0c;我也会放上参考文章链接。 学习重点 Android系统的四大组件&#xff1a; &#xff08;1&#xff09;活动&#xff…...

Educational Codeforces Round 146 (Rated for Div. 2)(VP)

写个题解 A. Coins void solve(){ll n, k; cin >> n >> k;bl ok true;if (n &1 && k %2 0) ok false;print(ok ? yes : no); } B. Long Legs void solve(){db x, y; cin >> x >> y;if (x < y) swap(x, y);int t1 ceil(sqrt(x))…...

9.30国庆

消息队列完成进程间通信 #include <myhead.h>#define size sizeof(msg_ds)-sizeof(long) //正文大小//消息结构体 typedef struct {long msgtype; //消息类型char data[1024]; //消息正文 }msg_ds;//创建子线程构造体 void *task1(void *arg) {//创造第二个key值ke…...

java基础-第4章-面向对象(二)

一、static关键字 静态&#xff08;static&#xff09;可以修饰属性和方法。 称为静态属性&#xff08;类属性&#xff09;、静态方法&#xff08;类方法&#xff09;。 静态成员是全类所有对象共享的成员。 在全类中只有一份&#xff0c;不因创建多个对象而产生多份。 不必创…...

flex加 grid 布局笔记

<style> .flex-container { display: flex; height: 100%; /* 设置容器的高度 */ } .wide { display: flex; padding: 10px; border: 1px solid lightgray; text-align: center; justify-content: …...

告别Electron臃肿!用Tauri 2.0 + Rust打造你的第一个轻量级桌面应用(附完整项目结构解析)

从Electron到Tauri 2.0&#xff1a;用Rust重构现代桌面应用开发范式 当Electron应用体积膨胀到200MB起步时&#xff0c;我们不得不重新思考桌面开发的未来。Tauri 2.0的出现绝非偶然——这是前端开发者对性能与体验的集体觉醒。本文将带你深入这个基于Rust的轻量级框架&#xf…...

示波器安全操作与高压测量实践指南

示波器安全使用指南&#xff1a;从基础操作到高压测量实践1. 示波器使用安全概述示波器作为电子工程师的核心调试工具&#xff0c;其正确使用直接关系到测量结果的准确性和操作人员的人身安全。在实际工程应用中&#xff0c;约35%的测量事故源于不规范的示波器操作&#xff0c;…...

工业视觉代码交付总被退回?(甲方验收必查的6项硬性指标:实时性≤35ms、重复精度±0.015px、抗电磁干扰日志完备性)

第一章&#xff1a;工业视觉代码交付失败的典型归因分析工业视觉系统在产线部署阶段频繁遭遇代码交付失败&#xff0c;其根本原因往往并非算法性能不足&#xff0c;而是工程化落地环节存在系统性疏漏。以下从环境适配、数据闭环、接口契约三个维度展开典型归因。运行时环境不一…...

大模型进阶:掌握Function Calling和MCP,解锁AI生产力(收藏版)

本文深入探讨了Function Calling技术如何帮助大模型获取实时信息、执行任务&#xff0c;以及MCP协议在大模型与外部交互中的关键作用。文章阐述了从提示工程到RAG&#xff0c;再到Function Calling和MCP的技术演进路径&#xff0c;强调了这些技术如何使大模型从信息工具转变为生…...

从SuperGlue到LoFTR:无检测器特征匹配是如何“卷”出来的?技术演进深度解读

从SuperGlue到LoFTR&#xff1a;无检测器特征匹配的技术革命与范式迁移 在计算机视觉领域&#xff0c;特征匹配一直是三维重建、SLAM、图像配准等任务的核心基础。传统方法如SIFT、ORB等基于手工设计的特征检测与描述算法&#xff0c;在过去二十年里主导了这一领域。然而&#…...

2026 工程指南:为什么 AWS Bedrock + Claude 4.6 正在成为多 Agent 协作的底层首选?

进入 2026 年第一季度&#xff0c;大模型领域的竞争已经从“单纯的参数规模”转向了“端到端的工程效率”。随着 GPT-5.4 陷入推理成本高企的泥潭&#xff0c;Anthropic 联手亚马逊发布的 Claude 4.6 托管方案&#xff0c;正在通过 Amazon Bedrock 平台迅速收割企业级市场。作为…...

自动化立体仓库堆垛机设计(设计说明书+17张CAD图纸+开题报告+任务书+实习报告+中期检查报告+外文翻译)

自动化立体仓库堆垛机作为现代物流系统的核心设备&#xff0c;其设计需兼顾机械结构强度、运动控制精度与系统稳定性。该设计通过三维建模与力学仿真验证&#xff0c;确保堆垛机在高速运行时的结构可靠性&#xff0c;同时优化货叉伸缩机构与载货台升降导轨的配合间隙&#xff0…...

3步搞定Google Drive受保护PDF:高效下载完整指南

3步搞定Google Drive受保护PDF&#xff1a;高效下载完整指南 【免费下载链接】Google-Drive-PDF-Downloader 项目地址: https://gitcode.com/gh_mirrors/go/Google-Drive-PDF-Downloader 你是否曾遇到过这样的情况&#xff1f;在Google Drive中找到一个急需的技术文档或…...

全平台网络资源下载神器:一键获取微信视频号、抖音、QQ音乐等热门内容

全平台网络资源下载神器&#xff1a;一键获取微信视频号、抖音、QQ音乐等热门内容 【免费下载链接】res-downloader 资源下载器、网络资源嗅探&#xff0c;支持微信视频号下载、网页抖音无水印下载、网页快手无水印视频下载、酷狗音乐下载等网络资源拦截下载! 项目地址: http…...

别再死记硬背了!用Kahn算法搞定LeetCode 207课程表,保姆级C++代码逐行解析

从课程表到任务调度&#xff1a;Kahn算法在LeetCode 207中的实战应用 每次打开LeetCode看到那道课程表问题&#xff0c;你是不是也感到一阵头疼&#xff1f;先修课程、依赖关系、环状检测……这些概念堆在一起&#xff0c;简直比大学选课系统还让人崩溃。但别担心&#xff0c;今…...