felix-cao / Blog

A little progress a day makes you a big success!
31 stars 4 forks source link

centos 7 下 Nginx 的源码下载安装 #75

Open felix-cao opened 5 years ago

felix-cao commented 5 years ago

nginx 官网下载地址

一、下载

cd /home/
mkdir software
wget -c https://nginx.org/download/nginx-1.14.0.tar.gz

二、解压安装

tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure
make
make install

configure 命令执行后

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

查找安装路径

$ whereis nginx

三、启动、停止nginx

$ cd /usr/local/nginx/sbin/

./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload

./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。 ./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

四、重启 nginx

4.1.先停止再启动(推荐):

nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:

$ ./nginx -s quit
$ ./nginx

4.2.重新加载配置文件:

nginx 的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 nginx 再启动 nginx 即可将配置信息在 nginx 中生效,如下:

$ ./nginx -s reload

五、开机自启动

即在rc.local增加启动代码就可以了。

$ vi /etc/rc.local

增加一行 /usr/local/nginx/sbin/nginx 设置执行权限:

$ chmod 755 rc.local

六、可能需要安装依赖环境

6.1.、gcc 安装

安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

$ yum install gcc-c++

6.2、 PCRE pcre-devel 安装

PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginxhttp 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx 也需要此库。命令:

$ yum install -y pcre pcre-devel

6.3、 zlib 安装

zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlibhttp 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

$ yum install -y zlib zlib-devel

6.4、 OpenSSL 安装

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。 nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

yum install -y openssl openssl-devel

Error

可能80端口被占用:

netstat -anp|grep 80
felix-cao commented 4 years ago

-bash: make: command not found

yum -y install gcc automake autoconf libtool make