编辑文章 linuxnginx 本文以 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` <p>本文以 centos为例</p> <ul> <li><strong>开始前,请确认gcc g++开发类库是否装好</strong> 安装make:</li> </ul> <pre><code>yum -y install gcc automake autoconf libtool make </code></pre> <p>安装g++:</p> <pre><code>yum install gcc gcc-c++ </code></pre> <hr /> <p><strong>下面正式开始:</strong></p> <h2><strong>一、选定安装文件目录</strong></h2> <pre><code>[root@localhost ~]# cd /usr/local/nginx/ </code></pre> <h2>二、安装PCRE库</h2> <p> ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:</p> <pre><code>[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 </code></pre> <h2><strong>三、<strong>安装zlib库</strong></strong></h2> <p> http://zlib.net/zlib-1.2.11.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包</p> <pre><code>[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 </code></pre> <h2><strong>四、<strong>安装openssl</strong></strong></h2> <pre><code>[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 </code></pre> <p>//一键安装上面四个依赖 <code>yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel</code></p> <h2><strong>五、安装nginx</strong></h2> <p> 您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:</p> <pre><code>[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 </code></pre> <h2><strong>六、修改配置 启动nginx</strong></h2> <p>nginx.config添加一下模块</p> <pre><code>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; } } </code></pre> <p>启动测试</p> <pre><code>[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 </code></pre> <p>启动报错 从错误提示信息可以得知是因为缺少lib文件导致,进一步查看具体内容:</p> <pre><code>[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) </code></pre> <p>查看结果显示 : libpcre.so.1 => not found ,同时注意lib库的路径,有/lib/* 和 /lib64/* 之分。 创建的软连接</p> <pre><code>[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 </code></pre> <h2>操作命令</h2> <p>停止nginx <code>nginx -s stop</code> 启动 <code>nginx</code> 重启 <code>nginx -s reload</code></p> 标题: 分类: 请选择分类(必选) 博客 酷玩 分享 相册 标签: 按 Tab、回车或逗号把输入的文字变成标签;点 × 或在输入框为空时按退格删除;最多 8 个 封面图: 上传图片 建议尺寸 800x400,图片大小不超过 1MB 展开更多设置(关键词、摘要、转载、评论) 关键词: 摘要: 本文以 centos为例 开始前,请确认gcc g++开发类库是否装好 安装make: yum -y install gcc automake autoconf libtool make 安装g++: yum install gcc gcc... 选项: 是否转载 启用评论 勾选「是否转载」可标注文章来源,原文链接可留空。 正文: 保存修改