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

Nginx的安装配置和使用

最近有好几个地方用到了nginx,但是一直还没时间记录下nginx的安装、配置和使用,这篇文章可以将这块内容整理出来,方便大家一起学习~

安装

安装是相对简单一些的,直接使用yum即可。

yum install -y  nginx

 默认安装位置在/usr/sbin/nginx这个位置下

也可以通过命令查询

whereis nginx

会有多个输出

配置

配置文件默认在/etc/nginx下,主配置文件是:nginx.conf

配置内容解读

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;   #默认用户
worker_processes auto;  # 工作进程设定,auto含义是cpu数量-1
error_log /var/log/nginx/error.log;  # 定义错误日志的位置
pid /run/nginx.pid;             #设定pid的位置# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;   #  加载支持的模块events {        #事件worker_connections 1024;
}http {       #配置定义的http的信息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/access.log  main;   #http请求访问日志的位置sendfile            on;tcp_nopush          on;tcp_nodelay         on;keepalive_timeout   65;types_hash_max_size 4096;include             /etc/nginx/mime.types;default_type        application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;#扩展配置的路径,例如在对应的路径下增加配置文件即可。server {# 默认监听的端口listen       80;listen       [::]:80;server_name  _;root         /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;   #扩展配置的路径error_page 404 /404.html;location = /404.html {  #错误的默认访问页面}error_page 500 502 503 504 /50x.html;location = /50x.html {  #错误的默认访问页面}}
  • worker_processes 指定 Nginx 使用的 worker 进程数量。使用 auto 可以自动根据 CPU 核心数进行调整。
  • events 部分定义了 Nginx 的事件模型相关的设置,例如 worker_connections 指定每个 worker 进程可同时处理的连接数。
  • http 部分是配置 HTTP 服务相关的配置项。
  • include mime.types 指定了 MIME 类型的配置文件路径,用于解析文件类型。
  • default_type 指定了默认的 MIME 类型。
  • sendfile on 开启了 sendfile 功能,可以提高文件传输效率。
  • keepalive_timeout 指定了 keepalive 连接的超时时间。
  • server 定义了一个虚拟主机(server block),其中 listen 指定了监听的端口和 IP。
  • location / 是一个 location 块,指定了请求的 URI 以 / 开头时的处理方式。
  • root 指定了网站文件的根目录。
  • index 指定了默认的主页文件。
  • error_page 定义了一些错误页面的处理方式,例如 404 页面和 50x(500、502、503、504)错误页面。
http://www.lryc.cn/news/280671.html

相关文章:

  • P1643 完美数 题解
  • docker一键安装
  • 模板管理支持批量操作,DataEase开源数据可视化分析平台v2.2.0发布
  • 阿里云实时计算企业级状态存储引擎 Gemini 技术解读
  • web缓存之nginx缓存
  • 【用法总结】无障碍AccessibilityService
  • AI绘画风格化实战
  • 008定点小数、奇偶校验码
  • 一、二进制方式 安装部署K8S
  • 【simple-admin】FMS模块如何快速接入阿里云oss 腾讯云cos 服务 实现快速上传文件功能落地
  • 数据结构.线性表(2)
  • 【计算机网络】TCP原理 | 可靠性机制分析(三)
  • 【昕宝爸爸小模块】线程的几种状态,状态之间怎样流转
  • ChatGPT网站小蜜蜂AI更新了
  • 瑞_Java开发手册_(二)异常日志
  • Elasticsearch:Search tutorial - 使用 Python 进行搜索 (四)
  • Python之Matplotlib绘图调节清晰度
  • pygame.error: video system not initialized
  • java面试题2024
  • 配置git服务器
  • vue3环境下,三方组件中使用echarts,无法显示问题
  • FAST OS DOCKER 可视化Docker管理工具
  • MOJO基础语法
  • java基础之IO流之字符流
  • chromium通信系统-ipcz系统(十一)-mojo binding
  • 鸿蒙开发基础-Web组件之cookie操作
  • 什么是k8s和声明式编程?
  • Fluids —— MicroSolvers DOP
  • 工业智能网关:HiWoo Box远程采集设备数据
  • Apollo之原理和使用讲解