欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

记一次安装nginx遇到的问题

程序员文章站 2022-05-11 10:54:25
...
  1. 下载http://nginx.org/en/download.html
  2. 将下载下来的Nginx上传到/usr/local/nginx/目录下。运行“tar -zxvf nginx-1.13.6.tar.gz”进行解压。
  3. 切换到/usr/local/nginx/nginx-1.13.6目录下,运行./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=<path> option.

百度 the HTTP rewrite module requires the PCRE library.
却少pcre。
查询一下,发现nginx已经有了自带pcre
find / -name "pcre"
/usr/local/nginx/nginx-1.13.6/auto/lib/pcre
于是指定pcre路径运行 ./configure
./configure --with-pcre=/usr/local/nginx/nginx-1.13.6/auto/lib/pcre
运行这个问题就没了

但依然报错
./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.

于是同样的解决办法
./configure --with-pcre=/usr/local/nginx/nginx-1.13.6/auto/lib/pcre --with-zlib=/usr/local/nginx/nginx-1.13.6/auto/lib/zlib

初始化配置解决了。

  1. 编译 make
依然报错
make -f objs/Makefile
make[1]: 进入目录“/usr/local/nginx/nginx-1.13.6”
cd /usr/local/nginx/nginx-1.13.6/auto/lib/pcre \
&& if [ -f Makefile ]; then make distclean; fi \
&& CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared 
/bin/sh:行2: ./configure: 没有那个文件或目录
make[1]: *** [/usr/local/nginx/nginx-1.13.6/auto/lib/pcre/Makefile] 错误 127
make[1]: 离开目录“/usr/local/nginx/nginx-1.13.6”
make: *** [build] 错误 2

找不到.configure文件,进入/usr/local/nginx/nginx-1.13.6/auto/lib/pcre/
确实是没有./configure文件
懒得动了,直接换一种解决方法,重新下载pcre安装,将--with-pcre指定到安装的路径

pcre安装过程
1.下载pcre https://sourceforge.net/projects/pcre/files/pcre/并上传服务器
使用tar -zxvf pcre-8.41.tar.gz进行解压。
2. 运行 chmod -R 777 pcre-8.41 对当前文件夹授予全部读写权限。
3. 切换到pcre-8.41目录下,运行 ./configure 进行pcre初始化配置 运行./configure。
然而又报错:
error: You need a C++ compiler for C++ support.
直接yum安装 yum install -y gcc gcc-c++
重新运行./configure,好了。
4. make&&make install
ok
zlib用了yum安装(度娘给的结果)
yum install -y zlib-devel
  1. 继续初始化nginx ,运行./configure --with-pcre=/usr/local/nginx/pcre-8.41
后续使用中却少ssh模块修改此安装过程。
[emerg] the "ssl" parameter requires ngx_http_ssl_module in ...
http转https添加ngx_http_ssl_module编译
1. yum install openssl-devel
2. ./configure --with-pcre=/usr/local/tool/pcre-8.41 --with-http_stub_status_module --with-http_ssl_module
  1. 编译安装
    make&&make install
  2. 注册为服务
[[email protected] nginx-1.13.6]# whereis nginx
nginx: /usr/local/nginx
[[email protected] nginx-1.13.6]# vim /etc/init.d/nginx
添加如下内容
#! /bin/sh
# chkconfig: - 85 15

PATH=/usr/local/nginx/sbin

DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}

do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

添加为服务
[[email protected] init.d]# chkconfig --add nginx
修改nginx文件权限
[[email protected] local]# chmod -R 777 nginx
启动nginx
[[email protected] local]# service nginx start
查看进程
[[email protected] local]# ps -aux|grep nginx
root     31029  0.0  0.0  18132   600 ?        Ss   22:34   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   31030  0.0  0.0  18572  1068 ?        S    22:34   0:00 nginx: worker process
root     31035  0.0  0.0 112664   976 pts/0    R+   22:36   0:00 grep --color=auto nginx
  1. 设置开机自启
    chkconfig nginx on

然而,网上有很多安装教程可以避免这些问题。
http://www.linuxidc.com/Linux/2016-09/134907.htm

转载于:https://www.jianshu.com/p/7ce8fa5775cb