nginx简介与安装配置,目录结构和配置文件介绍

news2024/9/24 7:23:43

一.nginx简介

1.简介

2.特性

二.nginx安装

1.rpm包方式

(1)下载扩展源

(2)安装扩展rpm包,nginx -V查看配置参数,后面源码安装时要用到

2.源码方式

(1)建议提前下好所需要的部分包

(2)下载tar.gz包

(3)建议将包解压到/usr/local/src下,执行configure文件

(4)安装好上面需要的包,继续执行第一步 

(5)一直到这步,configure文件就执行好了 

(6)make,make install编译安装

三.nginx部分目录结构

1.conf目录

2.html目录

四.nginx配置文件说明


一.nginx简介

1.简介

nginx是一个轻量级的网页服务器、方向代理服务器和电子邮件代理服务器,具有配置灵活、静态资源高并发、系统资源占用少、拥有缓存服务等优点。

2.特性

(1)对于静态资源,高速,高并发访问和缓存,支持htto相应速率限制

(2)支持使用反向代理加速,缓存数据

(3)可实现负载均衡和节点健康检查

(4)支持FastCGI,SCGI,Memcached Servers等服务的急速和缓存

(5)支持基于域名、端口、IP的虚拟主机站点代理,可以进行访问控制

(6)支持Keep-alive和pipelined连接

(7)在代码上线时可以平滑重启,不影响基本功能

(8)可以对日志进行格式自定义、临时缓冲、快速轮训和rsyslog处理

(9)支持信号控制nginx进程

(10)支持url重写和正则表达式匹配

(11)支持PUT、DELETE、MKCOL、COPY、MOVE等特殊http请求方法

(12)支持邮件服务代理

二.nginx安装

前提要卸载或关闭apache的httpd

[root@localhost ~]# systemctl stop httpd
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

1.rpm包方式

(1)下载扩展源

(2)安装扩展rpm包,nginx -V查看配置参数,后面源码安装时要用到

[root@localhost ~]# yum install https://nginx.org/packages/centos/7Server/x86_64/RPMS/nginx-debuginfo-1.22.0-1.el7.ngx.x86_64.rpm
[root@localhost ~]# yum install nginx-1.22.0-1.el7.ngx.x86_64.rpm -y
[root@localhost ~]# nginx -v
nginx version: nginx/1.22.0
[root@localhost ~]# nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

安装完成 

2.源码方式

(1)建议提前下好所需要的部分包

[root@localhost nginx-1.22.0]# yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

(2)下载tar.gz包

(3)建议将包解压到/usr/local/src下,执行configure文件

[root@localhost nginx-1.22.0]# pwd
/usr/local/src/nginx-1.22.0

[root@localhost nginx-1.22.0]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
#弹出来缺什么就安装它的开发包(devel)

(4)安装好上面需要的包,继续执行第一步 

[root@localhost nginx-1.22.0]# yum install -y pcre-devel 
[root@localhost nginx-1.22.0]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

[root@localhost nginx-1.22.0]# yum install -y openssl-devel
[root@localhost nginx-1.22.0]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

(5)一直到这步,configure文件就执行好了 

(6)make,make install编译安装

[root@localhost nginx-1.22.0]# make 
[root@localhost nginx-1.22.0]# make install
[root@localhost nginx-1.22.0]# nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

安装完成 

三.nginx部分目录结构

1.conf目录

[root@localhost nginx-1.22.0]# ll
total 804
drwxr-xr-x 6 1001 1001    326 Aug  9 19:25 auto
-rw-r--r-- 1 1001 1001 317070 May 24  2022 CHANGES
-rw-r--r-- 1 1001 1001 484445 May 24  2022 CHANGES.ru
drwxr-xr-x 2 1001 1001    168 Aug  9 20:30 conf
-rwxr-xr-x 1 1001 1001   2590 May 24  2022 configure
drwxr-xr-x 4 1001 1001     72 Aug  9 19:25 contrib
drwxr-xr-x 2 1001 1001     40 Aug  9 19:25 html   # Nginx 的默认站点目录
-rw-r--r-- 1 1001 1001   1397 May 24  2022 LICENSE
-rw-r--r-- 1 root root    387 Aug  9 19:49 Makefile
drwxr-xr-x 2 1001 1001     21 Aug  9 19:25 man
drwxr-xr-x 3 root root    174 Aug  9 20:26 objs
-rw-r--r-- 1 1001 1001     49 May 24  2022 README
drwxr-xr-x 9 1001 1001     91 Aug  9 19:25 src

[root@localhost nginx-1.22.0]# pwd
/usr/local/src/nginx-1.22.0

[root@localhost nginx-1.22.0]# tree conf
conf
├── fastcgi.conf   # fastcgi 相关参数的配置文件
├── fastcgi_params   # fastcgi 的参数文件
├── koi-utf
├── koi-win
├── mime.types   # 媒体类型
├── nginx.conf    # Nginx默认的主配置文件
├── scgi_params
├── uwsgi_params
└── win-utf

0 directories, 9 files

2.html目录

[root@localhost nginx-1.22.0]# tree html
html
├── 50x.html   # 错误页面替代显示文件,出现错误时调用这个页面
└── index.html   # 默认的首页文件, 在实际环境中,一般用index.html、 index.php或index.jsp来做

 

四.nginx配置文件说明

[root@localhost ~]# vim /etc/nginx/nginx.conf #rpm包在这个文件,源码安装的配置文件是/usr/local/src/nginx-1.22.0/conf/nginx.conf 
user  nginx;     #用户
worker_processes  auto;    #主模块命令,指定bnginx要开启的进程数,一般指定一个,如果cpu多多和,则和cpu数量一致即可

error_log  /var/log/nginx/error.log notice;   #主模块命令,全局错误日志,debug(最详细),info,notice,warn,error,crit(最简略)
pid        /var/run/nginx.pid;  #主模块命令,指定进程id的存储文件位置

#events指定设定nginx的工作模式和连接上限
events { 
    #use 模式      (事件模块指令,放在events中指定nginx的工作模式,select-标准工作模式,poll-标准工作模式,kqueue-BDS系统高效工作模式,epoll-Linux平台首选高效工作模式,rtsig,/dev/poll)
    worker_connections  1024;   #事件模块指令,定义每个进程的最大连接数,默认1024,max_client客户端连接数=worker_processes*worker_connections,max_clients=worker_processes*worker_connections/4,当然这些设置也受文件系统打开数量限制,执行名“ulimit -n 65535”后生效
}

#http服务配置
http {
    include       /etc/nginx/mime.types;    #include主模块命令,include配置文件
    default_type  application/octet-stream;  #http核心模块指令,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/access.log  main;

    sendfile        on;   #高效传输模式
    #tcp_nopush     on;

    keepalive_timeout  65;   #超时时间
	server {                    #server 区块
		listen 80;          #端口
	server_name localhost;      #域名
	location / {               #location区块,可以写多个
		root html;           #站点目录,路径不定,按我的源码安装方式那就在/usr/local/src/nginx-1.22.0/html
		index index.html index.htm;     #首页文件
		} 
	error_page 500 502 503 504 /50x.html;        #错误信息配置
	location = /50x.html {         #html文件位置
		root html;          #路径
		}
	}
    #gzip  on;  #是否开启压缩
include /etc/nginx/conf.d/*.conf;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/854738.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C语言系列之原码、反码和补码

一.欢迎来到我的酒馆 讨论c语言中,原码、反码、补码。 目录 一.欢迎来到我的酒馆二.原码 二.原码 2.1在计算机中,所有数据都是以二进制存储的,但不是直接存储二进制数,而是存储二进制的补码。原码很好理解,就是对应的…

Python读取excel数据并创建文件目录树-全解析过程及逻辑

需求描述: 需要将以下excel内的结构解析,并创建对应的文件目录 实现思路: 实现思路是通过解析Excel文件中的目录结构,并根据目录结构创建对应的文件夹。 具体的实现步骤如下: 1. 加载指定的Excel文件&#xff0c…

阿里云内容审核服务使用(图片审核)

说明:在项目中,我们经常会对用户上传的内容(如文字、图片)等资源内容进行审核,审核包括两方面,一方面是内容与描述不符,一方面是违反法律法规。本文介绍使用阿里提供的内容审核服务,…

《算法竞赛·快冲300题》每日一题:“最大团”

《算法竞赛快冲300题》将于2024年出版,是《算法竞赛》的辅助练习册。 所有题目放在自建的OJ New Online Judge。 用C/C、Java、Python三种语言给出代码,以中低档题为主,适合入门、进阶。 文章目录 题目描述题解C代码Java代码Python代码 “ 最…

zookeeperAPI操作与写数据原理

要执行API操作需要在idea中创建maven项目 (改成自己的阿里仓库)导入特定依赖 添加日志文件 上边操作做成后就可以进行一些API的实现了 目录 导入maven依赖: 创建日志文件: 创建API客户端: (1&#xff09…

Java实现八皇后问题

八皇后问题说明 八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例。该问题是国际西洋棋棋手马克斯贝瑟尔于 1848 年提出:在 88 格的国际象棋上摆放八个皇后,使其不能互相攻击,即:任意两个皇后都不…

【数据库】Redis可以替代Mysql吗

Redis和Mysql的搭配 Redis可以替代Mysql吗什么是RedisRedis适用的场景以及优点Redis的缺点 什么是MysqlMysql的优点Mysql缺点 总结 Redis可以替代Mysql吗 Redis不能代替MySQL, Redis和MySQL只能是一种互补。 什么是Redis Redis是一种非关系型数据库,也…

IDEA全局设置MyBatis中写SQL语句提示

把这两个设置改成MySQL即可:

clickhouse 删除操作

OLAP 数据库设计的宗旨在于分析适合一次插入多次查询的业务场景,市面上成熟的 AP 数据库在更新和删除操作上支持的均不是很好,当然 clickhouse 也不例外。但是不友好不代表不支持,本文主要介绍在 clickhouse 中如何实现数据的删除&#xff0c…

获取Spring中bean工具类

获取Spring中bean工具类 工具类 package com.geekmice.springbootselfexercise.utils;import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org…

【分布式系统】聊聊流量和数据调度

对于分布式系统来说,除了监控层面、以及服务治理层面,还有两个层面流量和数据调度。流量调度其实比较好理解,就是用户请求的流量,如何按照一定的策略算法打到不同的机器上。以及如何实现一个高可用、高性能的流量调度平台。而数据…

《CUDA C++ Programming Guide》第二章 CUDA 编程模型概述

2.1 内核 CUDA C 通过允许程序员定义称为kernel的 C 函数来扩展 C&#xff0c;当调用内核时&#xff0c;由 N 个不同的 CUDA 线程并行执行 N 次&#xff0c;而不是像常规 C 函数那样只执行一次。 使用 __global__ 声明说明符定义内核&#xff0c;并使用新的 <<<...&g…

CTF PWN之精确覆盖变量数据

刚开始接触pwn的朋友在做pwn练习时可能会有这样的疑问&#xff0c;怎么做到精确覆盖变量数据呢&#xff1f; 我们做pwn练习之前需要先知道&#xff1a;命令行参数C语言的main函数拥有两个参数&#xff0c;为int类型的argc参数&#xff0c;以及char**类型argv参数。其中argc参数…

进入现代云技术的世界-APIGateway、ServiceMesh、OpenStack、异步化框架、云原生框架、命令式API与声明式API

目录 APIGateway Service Mesh OpenStack 异步化框架 云原生框架 命令式API与声明式API APIGateway API网关&#xff08;API Gateway&#xff09;是一个服务器——充当了客户端和内部服务之间的中间层。API网关负责处理API请求&#xff0c;将客户端的请求路由到相应的后端…

centos8.5本地yum源报错

在下载文件出现以下错误 [rootserver ~]# yum install gcc Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. RHEL8.5-BaseOS …

上海亚商投顾:沪指录得4连阴 N盟固利盘中最高涨近37倍

上海亚商投顾前言&#xff1a;无惧大盘涨跌&#xff0c;解密龙虎榜资金&#xff0c;跟踪一线游资和机构资金动向&#xff0c;识别短期热点和强势个股。 市场情绪 沪指今日延续调整走势&#xff0c;科创50指数跌超1%&#xff0c;创业板指则较为抗跌。医药医疗股集体爆发&#xf…

【网络基础实战之路】实现RIP协议与OSPF协议间路由交流的实战详解

系列文章传送门&#xff1a; 【网络基础实战之路】设计网络划分的实战详解 【网络基础实战之路】一文弄懂TCP的三次握手与四次断开 【网络基础实战之路】基于MGRE多点协议的实战详解 【网络基础实战之路】基于OSPF协议建立两个MGRE网络的实验详解 PS&#xff1a;本要求基于…

Pytorch深度学习-----神经网络模型的保存与加载(VGG16模型)

系列文章目录 PyTorch深度学习——Anaconda和PyTorch安装 Pytorch深度学习-----数据模块Dataset类 Pytorch深度学习------TensorBoard的使用 Pytorch深度学习------Torchvision中Transforms的使用&#xff08;ToTensor&#xff0c;Normalize&#xff0c;Resize &#xff0c;Co…

前端先行模拟接口(mock+expres+json)

目录 mock模拟数据&#xff1a;data/static.js 路由&#xff1a;index.js 服务器&#xff1a;server.js yarn /node 启动服务器&#xff1a;yarn start 客户端&#xff1a;修改代理路径(修改设置后都要重启才生效) 示例 后端框架express构建服务器 前端发起请求 静态数…

Power BI中实现购物篮分析详解

一、购物篮分析简介 相信&#xff0c;很多人都听过沃尔玛购物篮分析的故事---“啤酒和尿布湿“&#xff0c;即分析购买尿布湿的顾客最喜欢购买的商品是什么&#xff1f;&#xff08;啤酒&#xff09;。在零售终端经营中&#xff0c;通过购物篮分析&#xff0c;分析不同商品之间…