centos7 安装nginx

第一步:.下载nginx,上传centos7, 最新版本1.14.0 ,下载地址:  http://nginx.org/en/download.html 

第二步: 先安装nginx依赖的包:

nginxC语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境。

 gcc

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

yum install gcc-c++

 PCRE

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginxhttp模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

yum install -y pcre pcre-devel

注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。

zlib

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

yum install -y zlib zlib-devel

 openssl

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。

nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

yum install -y openssl openssl-devel

第三步:解压后,进入解压目录,进行configure

./configure

--prefix=/home/nginx/nginx_1/nginx

--pid-path=/home/nginx/nginx_1/nginx/nginx.pid

--lock-path=/home/nginx/nginx_1/nginx.lock

--error-log-path=/home/nginx/nginx_1/log/nginx/error.log

--http-log-path=/home/nginx/nginx_1/log/nginx/access.log

--with-http_gzip_static_module

--http-client-body-temp-path=/home/nginx/nginx_1/temp/nginx/client

--http-proxy-temp-path=/home/nginx/nginx_1/temp/nginx/proxy

--http-fastcgi-temp-path=/home/nginx/nginx_1/temp/nginx/fastcgi

--http-uwsgi-temp-path=/home/nginx/nginx_1/temp/nginx/uwsgi

--http-scgi-temp-path=/home/nginx/nginx_1/temp/nginx/scgi

注意: 路径必须存在

第四步:make

第五步:make install

第六步:测试

1、启动:进入nginxsbin目录,./nginx就可以启动。

如果访问不到,首先查看防火墙是否关闭。

2关闭nginx

可以使用kill命令,但是不推荐使用。

推荐使用:./nginx -s stop

3、刷新配置:./nginx -s reload

原文地址:https://www.cnblogs.com/maohuidong/p/9386425.html