本文以 centos为例
- 开始前,请确认gcc g++开发类库是否装好 安装make:
yum -y install gcc automake autoconf libtool make
安装g++:
yum install gcc gcc-c++
下面正式开始:
一、选定安装文件目录
[root@localhost ~]# cd /usr/local/nginx/
二、安装PCRE库
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:
[root@localhost nginx]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
[root@localhost nginx]# tar -zxvf pcre-8.39.tar.gz
[root@localhost nginx]# ./configure
[root@localhost nginx]# make
[root@localhost nginx]# make install
三、安装zlib库
http://zlib.net/zlib-1.2.11.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包
[root@localhost nginx]# wget http://zlib.net/zlib-1.2.11.tar.gz
[root@localhost nginx]# tar -zxvf zlib-1.2.11.tar.gz
[root@localhost nginx]# cd zlib-1.2.11 ./configure
[root@localhost nginx]# make
[root@localhost nginx]# make install
四、安装openssl
[root@localhost nginx]# wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
[root@localhost nginx]# tar -zxvf openssl-1.0.1t.tar.gz
//一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
五、安装nginx
您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:
[root@localhost nginx]# wget http://nginx.org/download/nginx-1.1.10.tar.gz
[root@localhost nginx]# tar -zxvf nginx-1.1.10.tar.gz
[root@localhost nginx]# cd nginx-1.1.10
[root@localhost nginx]# ./configure
[root@localhost nginx]# make
[root@localhost nginx]# make install
六、修改配置 启动nginx
nginx.config添加一下模块
server {
listen 80;
server_name www.dafeiyu.cn dafeiyu.cn; #要访问的域名,如果有多个,用逗号分开
charset utf8;
location / {
proxy_pass http://23.105.218.71:9090/; #dafeiyu-tomcat管理中心 反向代理配置方式
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
启动测试
[root@localhost nginx]# sbin/nginx -t
sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
启动报错 从错误提示信息可以得知是因为缺少lib文件导致,进一步查看具体内容:
[root@localhost nginx]# ls /lib/ |grep pcre
libpcre.so.0
libpcre.so.0.0.1
[root@localhost nginx]# ldd $(which /usr/local/nginx/sbin/nginx)
linux-gate.so.1 => (0xb77c7000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb77a6000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7776000)
libpcre.so.1 => not found
libz.so.1 => /lib/libz.so.1 (0xb7762000)
libc.so.6 => /lib/libc.so.6 (0xb75ca000)
/lib/ld-linux.so.2 (0xb77c8000)
libfreebl3.so => /lib/libfreebl3.so (0xb7567000)
libdl.so.2 => /lib/libdl.so.2 (0xb7562000)
查看结果显示 : libpcre.so.1 => not found ,同时注意lib库的路径,有/lib/* 和 /lib64/* 之分。 创建的软连接
[root@localhost nginx]# ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1
[root@localhost 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
操作命令
停止nginx nginx -s stop
启动 nginx
重启 nginx -s reload
注意:本文归作者所有,未经作者允许,不得转载