①nginx 安装简介

https://w3techs.com/technologies/overview/web_server web服务排名
nginx程序功能介绍
特点:nginx因具有高并发(特别是静态资源)、占用系统资源少等特性
功能:nginx程序功能强大
1)可以满足web服务应用 apache 蓝汛
2)可以满足负载均衡应用 LVS Haproxy
3)可以满足缓存应用 Squid
局限:无法处理动态资源请求

盗链概念:网站图片被别的站点引用
网站服务apache vs nginx
01. 从特点进行说明   nginx高并发 占用物理资源少
02. 从功能方面说明   功能多  负载均衡  方便学习 容易上手
03. 从软件网络模型   网络编程 socket 
    select:apache  
	事件01: 宿舍管理员  找人---一个一个房间进行查找(遍历)
	事件02:幼儿园阿姨  负责看住小孩上厕所---一个一个进行确认
	epoll: nginx
    事件01: 宿舍管理员  找人---查找名单册
    事件02:幼儿园阿姨  负责看住小孩上厕所---有感觉就站到教室圈里

nginx软件部署安装过程:

1)利用yum安装软件:
   官方源安装:最新稳定版软件  目录结构信息(企业环境相符)
   其他源安装:稳定版软件	   目录结构信息(企业环境不太相符)  
2)利用编译方式安装:自定义安装功能 自定义程序安装的目录
   第一步:解决软件依赖关系
   第二步:进行软件配置过程  配置软件目录  指定软件功能
   第三步:进行软件编译过程  翻译解释的过程   C-gcc  python-python解释器
   第四步:进行软件编译安装

web01:采用官方源安装

第一个历程:修改yum源

官方参考:http://nginx.org/en/linux_packages.html#RHEL-CentOS
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
第二个历程:清除yum缓存信息
yum clean all
第三个历程:yum安装软件
yum install -y nginx
第四个历程: 管理nginx

查看nginx的状态

systemctl status nginx  

启动nginx服务

systemctl start  nginx   

硬重启nginx服务

systemctl restart nginx  

软重启nginx服务

systemctl reload  nginx  

Nginx编译安装软件

第一步:下载源码包

mkdir /server/tools -p
cd /server/tools
wget http://nginx.org/download/nginx-1.18.0.tar.gz

补充:解决软件依赖:

yum install -y pcre-devel

说明:pcre-perl兼容正则表达式
未安装报错信息:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

yum install -y openssl-devel

说明:openssl-devel 实现支持HTTPs 需要有私钥 公钥(证书)
未安装报错信息:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.

 yum install -y gcc-c++ -y

说明:gcc c语言的解释器(nginx -- c语言 python)
checking for OS
+ Linux 2.6.32-642.el6.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

第二步:解压源码包

tar xf nginx-1.18.0.tar.gz

第三步:软件编译配置过程

cd nginx-1.18.0/
useradd www -s /sbin/nologin -M
./configure  --prefix=/application/nginx-1.18.0  --user=www --group=www --with-http_ssl_module  --with-http_stub_status_module
--prefix=PATH                      set installation prefix
	                                   指定软件程序安装目录(不需要创建)
--user=USER                        set non-privileged user for worker processes
	                                   为worker进程设置一个非特权用户(必须存在)
--group=GROUP                      set non-privileged group for worker processes
	                                   为worker进程设置一个非特权用户组(必须存在)
--with-http_ssl_module             enable ngx_http_ssl_module
	                                   启用HTTPS功能
--with-http_stub_status_module     enable ngx_http_stub_status_module
	                                   启动nginx状态监控功能

第四步:编译过程

make

第五步:编译安装

make install

第六步:程序目录创建软链接

ln -s /application/nginx-1.16.0/ /application/nginx
 ln -s /application/nginx/sbin/nginx  /usr/local/bin/

第七步:设置systemd管理
cat /lib/systemd/system/nginx.service

[Unit]
Description=nginx service
After=network.target
 
   
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

nginx程序目录结构信息

参见图 
/etc/nginx/nginx.conf      --- 主配置文件
/etc/nginx/*cgi(通用接口)  --- nginx(无法处理动态请求) -fast_cgi- php   
                                                         -uwsgi   - python
原文地址:https://www.cnblogs.com/yangtao416/p/14602725.html