进入:/usr/java/nginx位置
下载nginx: wget http://nginx.org/download/nginx-1.8.0.tar.gz
下载openssl : wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz
下载zlib : wget http://zlib.net/zlib-1.2.8.tar.gz
下载pcre : wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
如果没有安装c++编译环境,还得安装,通过yum install gcc-c++完成安装
下一步,编译安装 openssl :[root@localhost] tar zxvf openssl-fips-2.0.9.tar.gz [root@localhost] cd openssl-fips-2.0.9 [root@localhost] ./config && make && make install
pcre安装:[root@localhost] tar zxvf pcre-8.36.tar.gz [root@localhost] cd pcre-8.36 [root@localhost] ./configure && make && make install
zlib安装:[root@localhost]tar zxvf zlib-1.2.8.tar.gz [root@localhost] cd zlib-1.2.8 [root@localhost] ./configure && make && make install
最后安装nginx[root@localhost]tar zxvf nginx-1.8.0.tar.gz [root@localhost] cd nginx-1.8.0 [root@localhost] ./configure && make && make install
出现错误提示
[root@localhost lib]# error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
原因 在RedHat 64位机器上nginx读取的pcre文件为/lib64/libpcre.so.1文件,默认安装pcre时libpcre.so文件安装在/usr/local/lib/目录下,所以输入/opt/nginx/sbin/nginx -V 找不到文件路径!!
1.首先确定安装了pcre.
2.root权限下添加软链接 /usr/local/lib/libpcre.so.1 到 /lib64/ : ln -s /usr/local/lib/libpcre.so.1 /lib64/
3.切换路径执行如下命令:
#cd /usr/local/lib #ln -s /usr/local/lib/libpcre.so.1 /lib64/
Nginx安装完毕,然后使用命令:/usr/local/nginx/sbin/nginx -t 测试OK,代表nginx安装成功。
验证安装查看一下Nginx的帮助信息:#/usr/local/nginx/sbin/nginx -h
测试当前Nginx默认配置文件/usr/java/nginx/nginx-1.8.0/conf /nginx.conf 是否可用,执行如下命令:
[root@localhost conf]# sudo /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动服务
如果使用默认的配置文件/usr/java/nginx/nginx-1.8.0/conf/nginx.conf来启动Nginx,执行如下命令:
<span style="color: rgb(68, 68, 68); font-family: Verdana, Geneva, sans-serif; font-size: 15px; line-height: 25.5px; orphans: 4; background-color: rgb(242, 242, 242);"></span><pre name="code" class="html">[root@localhost conf]# sudo /usr/local/nginx/sbin/nginx
如果修改了配置文件,需要重新加载,则可以执行如下命令: [root@localhost conf]# sudo /usr/local/nginx/sbin/nginx -s reload 如果指定一个配置文件,例如:/home/shirdrn/servers/nginx/conf/nginx.conf,可以执行如下命令: [root@localhost conf]# sudo /usr/local/nginx/sbin/nginx -c /home/shirdrn/servers/nginx/conf/nginx.conf 终止服务 终止Nginx服务,有两种模式: 一种是立即强制停止服务,执行如下命令: [root@localhost conf]# sudo /usr/local/nginx/sbin/nginx -s stop 另一种是比较优雅的方式,不再接收新到达的请求,等待已经处理的请求完成,执行如下命令: [root@localhost conf]# sudo /usr/local/nginx/sbin/nginx -s quit
/usr/local/nginx/sbin/nginx 回车启动nginx,可以通过访问http://ip/看到nginx默认页面。