nginx安装及安装中遇到的问题

一、准备工作

Nginx安装版本:nginx-1.8.1.tar.gz

Linux环境:   先执行这个  yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

二、安装nginx

1、把nginx安装包放到/usr/locad下

2、解压安装包:tar -xvf nginx-1.8.1.tar.gz

3、修改安装包名称:mv nginx-1.8.1 nginx

4、进入nginx目录:cd nginx 

5配置  执行

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf

6、编译安装make && make install

三、验证是否安装成功

1、在/usr/local/nginx/sbin目录执行./nginx 启动nginx  

修改配置后执行这条命令: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  

2.在浏览器中输入http://ip:80出现如下界面,表示启动成功

nginx安装及安装中遇到的问题_第1张图片

四、安装中遇到的问题

1、问题1,执行./configure报错

./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= option.

解决办法:

执行:yum -y install pcre-devel命令即可

2、

执行./configure报错

./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= option.

执行yum -y install zlib-devel

3、./nginx 重启时报错

 nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)

解决方法:

提示没有这个文件,是因为在nginx目录下没有logs文件夹,创建一个在启动即可

cd /usr/local/nginx

mkdir logs

cd sbin

./nginx

4、目录为同一级

make[1]: Leaving directory `/usr/local/nginx'

make -f objs/Makefile install

make[1]: Entering directory `/usr/local/nginx'

test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'

test -d '/usr/local/nginx/sbin' || mkdir -p '/usr/local/nginx/sbin'

test ! -f '/usr/local/nginx/sbin/nginx' || mv '/usr/local/nginx/sbin/nginx' '/usr/local/nginx/sbin/nginx.old'

cp objs/nginx '/usr/local/nginx/sbin/nginx'

test -d '/usr/local/nginx/conf' || mkdir -p '/usr/local/nginx/conf'

cp conf/koi-win '/usr/local/nginx/conf'

cp: "conf/koi-win" "/usr/local/nginx/conf/koi-win" 为同一文件

make[1]: *** [install] 错误 1

make[1]: Leaving directory `/usr/local/nginx'

make: *** [install] 错误 2

 

这是因为编译安装过一次,再次编译安装时,sbin等文件夹已经存在所以会包这个错误,可以删除该文件夹再次安装,或者忽略该错误

5、

nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

使用/usr/local/nginx/sbin/nginx -s reload 重新读取配置文件出错

 

[root@localhost nginx]/usr/local/nginx/sbin/nginx -s reload

提示 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

 

[root@localhost nginx]# cd logs

[root@localhost logs]# ls

access.log error.log nginx-access.log nginx_error.log

果然没有/usr/local/nginx/logs/nginx.pid 文件

解决方法:用指定文件加载nginx配置文件

[root@localhost nginx]/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

搞定!!!

 

你可能感兴趣的:(nginx,linux,运维)