一、linux
安装环境
1、
需要安装
gcc
的环境。
yum install gcc-c++
2、
第三方的开发包。
PCRE
PCRE(Perl Compatible Regular Expressions)
是一个
Perl
库,包括
perl
兼容的正则表达式库。
nginx
的
http
模块使用
pcre
来解析正则表达式,所以需要在
linux
上安装
pcre
库。
yum install -y pcre pcre-devel
注:
pcre-devel
是使用
pcre
开发的一个二次开发库。
nginx
也需要此库。
zlib
zlib
库提供了很多种压缩和解压缩的方式,
nginx
使用
zlib
对
http
包的内容进行
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
二、
安装步骤
第一步:把
nginx
的源码包上传到
linux
系统
第二步:解压缩
[root@localhost ~]# tar zxf nginx-1.8.0.tar.gz
第三步:使用
configure
命令创建一
makeFile
文件。
prefix指定安装路径
./configure \
--prefix
=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
注意:启动
nginx
之前,上边将临时文件目录指定为
/var/temp/nginx
,需要在
/var
下创建
temp
及
nginx
目录
[root@localhost sbin]# mkdir /var/temp/nginx/client -p
第四步:
make
第五步:
make install
三、
启动
nginx
在
sbin
目录下执行
./nginx 即可启动
[root@localhost sbin]# ./nginx
启动后,通过 ps aux | grep nginx 命令需要查看到两个进程 master 和 worker。
关闭
nginx
:
[root@localhost sbin]# ./nginx -s stop
推荐使用:
[root@localhost sbin]# ./nginx -s quit
重启
nginx
:
1、
先关闭后启动。
2、
刷新配置文件:
[root@localhost sbin]# ./nginx -s reload
Nginx
的配置文件路径:
/nginx/conf/nginx.conf
四、
访问
nginx
默认是
80
端口。
注意:是否关闭防火墙。