阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux 下安装配置Nginx及常见问题解答

136次阅读
没有评论

共计 2809 个字符,预计需要花费 8 分钟才能阅读完成。

其实也不能完全算是原创吧!都是我配置 nginx 时所遇到的问题,查阅资料后总结起来。即是巩固一下 nginx 的配置,也是分享给新入 Linux 的童鞋们一些知识

好了,不多废话,进入主题吧!

为 nginx 添加 www 组及 www 用户

1
2
[root@hostname ~ ]groupadd www      // 添加 www 组
[root@hostname ~ ]useradd -g www www  // 添加 www 用户并加入 www 组

注:如果给 groud、passwd 等文件添加过不可更改属性,需要先取消权限锁定设置(这不是废话吗 = =!)

编译安装

1
2
3
4
[root@hostname ~ ]tar zxvf nginx-1.8.0.tar.gz  // 解压包
[root@hostname ~ ]./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --user=www --group=www // 安装 nginx 到 /usr/local/ 下,设置配置文件路径及用户
[root@hostname ~ ]make
[root@hostname ~ ]make install

对于 nginx 软件包,个人建议从官网下载

错误信息及解决方法

进行到 ./configure 这一步时报错,解决方法如下:

1
1)如果报错
 
1
2
3
4
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

说明 pcre 依赖软件没有安装或者没有安装成功。 安装 PCRE 依赖

1
2
3
4
5
[root@hostname ~]tar zxvf pcre-8.12.tar.gz
[root@hostname ~]cd pcre-8.12
[root@hostname ~]./configure
[root@hostname ~]make
[root@hostname ~]make install

   2)如果报错

1
2
3
4
5
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib
library
statically from the source with nginx by using –with-zlib=<path> option.

同上、zlib-devel 依赖没安装或安装失败。安装 zlib-devel 依赖

1
[root@hostname ~]yum install -y zlib-devel // 也可以软件包安装

这时再进行./configure make make install 即可完成安装。

 

启动 nginx 

1
[root@hostname ~]/usr/local/nginx/sbin/nginx /usr/local/nginx/conf/nginx.conf

如果报异常如下,说明我们环境还没有完全配置好

1
[root@hostname ~]/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决方法:进入 lib 目录下,直接输入

1
2
[root@hostname lib]ln -s /usr/local/lib/libpcre.so.1 /lib    //32 位系统
[root@hostname lib]ln -s /usr/local/lib/libpcre.so.1 /lib64  //64 位系统

       再启动 nginx,没有报错信息,查看 nginx 进程(至少要有一个 master 一个 worker)

1
2
3
[root@hostname ~]$ ps -aux | grep nginx
root 15913  0.0  0.0  19804  628 ?  Ss  11:58  0:00 nginx: master process /usr/local/nginx/sbin/nginx
www 15914  1.9  0.0  20720  2068 ?  S  11:58  3:11 nginx: worker process

到这一步,nginx 就已经配置成功了

Tips:非 root 用户不要忘记使用 sudo 进行上面的操作(这也是废话吧 = =!)

更多 Nginx 相关教程见以下内容

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

Ubuntu 16.04 下安装部署 Nginx+uWSGI+Django1.9.7  http://www.linuxidc.com/Linux/2016-07/133484.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Ubuntu 16.04 源码编译安装 Nginx 1.10.0  http://www.linuxidc.com/Linux/2016-08/134080.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-08/134297.htm 

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2809字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中