centos7 – nginx 安装
- 下载nginx安装包:https://nginx.org/en/download.html
- tar -zvxf nginx-1.20.2.tar.gz
- cd nginx-1.20.2
- ./configure
报错:
checking for OS
+ Linux 3.10.0-1127.el7.x86_64 x86_64
checking for C compiler … not found
./configure: error: C compiler cc is not found
解决:
yum -y install gcc
报错:
/var/run/yum.pid 已被锁定,PID 为 8047 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit…
另一个应用程序是:yum
内存: 27 M RSS (421 MB VSZ)
已启动: Wed Feb 9 14:44:06 2022 - 18:31之前
状态 :跟踪/停止,进程ID:8047解决:
ps aux|grep yum
kill -s 9 [pid]
报错:
./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 install -y pcre pcre-devel
- make
- make install
- cd /usr/local/nginx/sbin
- ./nginx
nginx 启动成功,浏览器无法访问
解决:
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service
nginx 操作
- 查看 nginx 版本信息:
nginx -v
报错:
-bash: nginx: 未找到命令
解决:
PATH=$PATH:/usr/local/nginx/sbin
- 重启 nginx :
./nginx -s reload
- 为 nginx 设置专用帐号
user nginx
后,nginx 访问报错 403 Forbidden
原因:权限问题,nginx 用户没有 index.html 的操作权限。
解决:暂时是把 nginx 的启动用户 nginx 改成目录的所属用户 root 了,即user root
,但这样不符合安全配置项:NGINX 使用非特权的专用服务帐号运行,可以尝试修改 index.html 所在目录的用户或为 nginx 用户授予 index.html 的操作权限。
- nginx 添加模块:
- 切换到源码目录:
cd /root/nginx-1.20.2
./configure --with-http_ssl_module
- 重新编译:
make
- 备份原来nginx配置文件:
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
- 保证nginx是关闭状态:
nginx -s stop
- 复制刚编译生成的配置覆盖原有的配置:
cp ./objs/nginx /usr/local/nginx/sbin/
- 启动nginx:
nginx