Linux ���安装配置Nginx及常见问题解答
其实也不能完全算是原创吧!都是我配置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_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically 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_moduleoption, or install the zlib library into the system, or build the zlib librarystatically 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 nginxroot 15913 0.0 0.0 19804 628 ? Ss 11:58 0:00 nginx: master process /usr/local/nginx/sbin/nginxwww 15914 1.9 0.0 20720 2068 ? S 11:58 3:11 nginx: worker process |
到这一步,nginx就已经配置成功了
Tips:非root用户不要忘记使用sudo进行上面的操作(这也是废话吧= =!)
更多Nginx相关教程见以下内容:
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里