nginx 安装配置

centos7 – nginx 安装

  1. 下载nginx安装包:https://nginx.org/en/download.html
  2. tar -zvxf nginx-1.20.2.tar.gz
  3. cd nginx-1.20.2
  4. ./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

  1. make
  2. make install
  3. cd /usr/local/nginx/sbin
  4. ./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 添加模块:
  1. 切换到源码目录:cd /root/nginx-1.20.2
    ./configure --with-http_ssl_module
  2. 重新编译:make
  3. 备份原来nginx配置文件:cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
  4. 保证nginx是关闭状态:nginx -s stop
  5. 复制刚编译生成的配置覆盖原有的配置:cp ./objs/nginx /usr/local/nginx/sbin/
  6. 启动nginx:nginx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值