centos6.5安装源码安装nginx

一:安装准备

网上下载nginx-1.8.0.tar.gz

准备gcc编译环境:

yum install gcc-c++

nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库:

yum install -y pcre pcre-devel

nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库:

yum install -y zlib zlib-devel

nginx不仅支持http协议,还支持https,所以需要在linux安装openssl库:

yum install -y openssl openssl-devel

二:编译安装

将下载的nginx-1.8.0.tar.gz上传到centos服务器

解压:

tar -zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0

设置编译参数,在nginx-1.8.0目录下直接copy执行

./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

注意:上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录,mkdir -p /var/temp/nginx

编译安装命令:

make

make install

三:启动

进入nginx目录执行启动命令:

cd /usr/local/nginx/sbin/

./nginx

查看进程,是否启动成功:

ps -ef | grep nginx

四:停止

方式1,快速停止:

cd /usr/local/nginx/sbin

./nginx -s stop

此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

方式2,完整停止(建议使用):

cd /usr/local/nginx/sbin

./nginx -s quit

此方式停止步骤是待nginx进程处理任务完毕进行停止。

五:重启nginx

方式1,先停止再启动(建议使用):

./nginx -s quit

./nginx

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

方式2,重新加载配置文件:

./nginx -s reload

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

六:测试

打开浏览器访问http://192.168.96.128/  ,看到如下欢迎页则安装成功

猜你喜欢

转载自blog.csdn.net/qq_15076569/article/details/83505684