CentOS7.9安装nginx

22 篇文章 0 订阅
3 篇文章 0 订阅

目录

1、下载

2、安装

3、相关问题


1、下载

官网下载地址

nginx: downloadhttps://nginx.org/en/download.html

 或者从这里下载:

nginx-1.21.6.zip和nginx-1.21.6.tar.gz-Java文档类资源-CSDN下载从官网上下载的版本,包括window版本和linux版本:nginx-1.21.6.zipng更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/fyihdg/85463070

下载后上传服务器

 解压

tar -xvf nginx-1.21.6.tar.gz 

2、安装

然后进入目录

安装, --prefix=/opt/nginx安装目录的意思

 ./configure --prefix=/opt/nginx

报错了:

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

 安装pcre-devel解决问题

yum -y install pcre-devel

再次安装

./configure --prefix=/opt/nginx

又报错:

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

执行:

yum install -y  zlib zlib-devel

 再次执行:

 ./configure --prefix=/opt/nginx

 然后执行

make

执行:

make install

 安装目录已经有文件了

 启动nginx

 ./nginx 

 浏览器输入IP,默认端口是80

安装完成

3、相关问题

如果不能访问,关闭防火墙

#开启防火墙
systemctl start firewalld

#关闭防火墙
systemctl stop firewalld

安装成服务的形式,创建服务脚本

vi /usr/lib/systemd/system/nginx.service

内容如下:

[Unit]
Description=nginx -  web server
After=network.target remote-fs.target nss-lookup.target
  
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
ExecQuit=/opt/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

重新加载系统服务

systemctl daemon-reload

启动服务

systemctl start nginx.service

开机启动

systemctl enable firewalld.service

ps -ef|grep nginx

 查出 nginx线程后,然后执行

systemctl start nginx.service

以后就可以用这样的命令去开启服务了,也可以查看状态

systemctl status nginx.service 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fyihdg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值