前言
首先找到一篇nginx安装教程,我参考的是
https://www.runoob.com/linux/nginx-install-setup.html
因为我使用的是阿里云环境可以连接外网,因此可以使用wget以及yum命令。
虽然是参考的教程,但还是有一些坑。
1.configure命令变动
将上图的命令修改为
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.35
这个地方就修改了prefix的位置,修改后的位置是默认的。同时去除–with-http_stub_status_module --with-http_ssl_module这两个配置。这两个配置会导致之后第4点错。
2.make命令报错一
src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[2] << 16;
~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
case 2:
^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[1] << 8;
~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
case 1:
^~~~
这个是把警告的命令都当成了报错,这个百度可以很轻松找到。
需要编辑nginx目录下的objs/Makefile文件,去除-Werror即可。
需要注意的是每次重新执行./configure命令后,该文件都会重置为修改前有-Werror的内容。因此执行./configure后需要再修改Makefile文件。
修改后重新执行make命令,上面的error就会变成warning。
3. make命令报错二
src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:
src/os/unix/ngx_user.c:35:7: error: ‘struct crypt_data’ has no member named ‘current_salt’
cd.current_salt[0] = ~salt[0];
^
这里根据百度,找到两种说法。
一种是因为系统版本为centos8,需要修改为centos7。这种方式没有尝试过。我采用的是另一种,找到对应的文件,将该部分内容注释掉。
然后接着重新执行make命令。
4. make命令报错三
关于ssl的配置编译报错。解决办法见1.configure命令变动
5.nginx命令
经过上述配置,在/usr/local下面可以看到nginx文件夹。在其下的sbin目录下可以执行nginx的命令。
nginx -v
查看nginx版本
nginx -s stop
停止nginx命令会遇到报错,是因为这时候都没有nginx在运行。
nginx: [error] invalid PID number "" in "/run/nginx.pid"
nginx -t
检查/etc/nginx/nginx.conf配置文件语法是否正确
nginx -c /etc/nginx/nginx.conf
编译执行nginx命令。执行这个命令后,就不会报错 invalid PID number “” in “/run/nginx.pid”
nginx -s reload
重新加载/etc/nginx/nginx.conf配置,用于nginx配置修改后执行,再重启。
nginx -s reopen
修改nginx.conf配置文件后,重启nginx。