1.gcc 可以编译 C,C++,Ada,Object C和Java等语言(安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境)
2.pcre pcre-devel pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库
3.zlib zlib-devel zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装
4.openssl openssl-devel OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
5.nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL
- yum install gcc-c++
-
- yum install -y pcre pcre-devel
-
- yum install -y zlib zlib-devel
-
- yum install -y openssl openssl-devel
下载nginx:
- wget http://nginx.org/download/nginx-1.22.1.tar.gz
-
解压:
tar -zvxf nginx-1.22.1.tar.gz
cd nginx-1.22.1
./configure 默认文件夹就在/usr/local/nginx/
1、./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=
[root@localhost nginx-1.22.1]# yum -y install pcre-devel
2、./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=
[root@localhost nginx-1.22.1]# yum -y install openssl openssl-devel
3、./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.
[root@localhost nginx-1.22.1]# yum install gd gd-devel -y
使用make && make install
cd /usr/local/nginx/sbin
./nginx
nginx的命令:
nginx -s reload 修改配置后重新加载生效
nginx -s stop 快速停止
nginx nginx -s start 启动
nginx nginx -s quit 完整有序的停止
nginx nginx -v 查看nginx的版本
nginx -V 查看版本和nginx的配置选项
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确
nginx -s reopen 重新打开日志文件
nginx降权:使用普通用户启动Nginx(监牢模式)
默认情况下,nginx的master进程使用的是root用户,worker进程使用的是nginx指定的普通用户,使用root用户跑nginx的master进程有两个大问题: (1)管理权限必须是root,这就使得最小化分配权限原则遇到问题 (2)使用root跑nginx服务,一旦网站出现漏洞,用户就可以很容易获得服务器的root权限
给nginx服务降权的解决方案
(1)给nginx服务降权,用inca用户跑nginx服务,给开发及运维人员设置普通账号,只要与inca同组即可管理nginx
(2)开发人员使用普通账户即可管理nginx服务及站点下的程序和日志 (3)采取项目负责制,即谁负责项目维护,出现问题就是谁负责
操作如下:创建普通用户
- useradd -d /home/inca -m inca
-
- passwd inca


设置权限:

- php php-fpm
-
- yum -y install php php-fpm php-gd php-mysql php-common php-pea


vim conf/nginx.conf

[root@localhost html]# ls 50x.html index.html [root@localhost html]# vim index.php [root@localhost html]# [root@localhost html]# [root@localhost html]# [root@localhost html]# cat index.php


