转:https://blog.csdn.net/u013641234/article/details/73838472
Nginx作为一个web服务器,目前使用最多的就利用其负载均衡,本篇着重讲解的是nginx在linux环境下的安装部署。
root环境下安装
1.准备资源,下载nginx及相关组件:
(1)、cd usr/local/src 进入下载目录,可自定义
(2)、准备下载4个程序:
wget http://nginx.org/download/nginx-1.10.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
如果安装了c++的环境就可跳过,如未安装:yum install gcc-c++ (点击y即可)
安装结尾显示complete,即代表安装完成
2.安装nginx及其组件
(1)、安装openssl:
tar -zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install 进入文件执行安装程序
(2)、安装pcre
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install
(3)、安装zlib
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
(4)、安装nginx
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
3.启动nginx
(1)、查看nginx安装的地址(whereis)
(2)、进入目录启动
cd /usr/local/nginx/
/usr/local/nginx/sbin/nginx
一般这个时候会报错,不要慌张!!!
错误信息:error while loading shared libraries:libpcre.so.1.......
解决方案:
[root@localhost nginx]# whereis libpcre.so.1
libpcre.so: /lib64/libpcre.so.0 /usr/local/lib/libpcre.so.1 /usr/local/lib/libpcre.so
[root@localhost nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64
[root@localhost nginx]# sbin/nginx
[root@localhost nginx]# ps -aux | grep nginx
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 12007 0.0 0.0 20296 628 ? Ss 13:28 0:00 nginx: master process sbin/nginx
nobody 12008 0.0 0.1 20716 1220 ? S 13:28 0:00 nginx: worker process
root 12010 0.0 0.0 103244 836 pts/0 S+ 13:29 0:00 grep nginx
4.测试安装是否成功:
进入linux自带的火狐浏览器,键入localhost,会跳出welcome to nginx!(切忌关闭防火墙)
service iptables stop(如果不关闭防火墙,可能会导致访问失败!)
over~~~