Nginx安装

1 下载安装包 http://nginx.org/en/download.html

2 解压

tar  -zxvf nginx-1.21.6.tar.gz

3 安装

cd nginx-1.21.6/
./configure --prefix=/usr/local/nginx
make
make install

4 如果出现问题或者警告

  • 提示1
checking for OS + Linux 3.10.0-693.el7.x86_64 x86_64 checking for C compiler ... not found ./configure: error: C compiler cc is not found 

安装 gcc
yum install -y gcc

  • 提示2
./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.

安装perl库
yum install -y pcre pcre-devel

  • 提示3
./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. 

安装zlib库
yum install -y zlib zlib-devel

5 启动nginx命令
进入安装好的目录 /usr/local/nginx/sbin

./nginx 启动 
./nginx -s stop 快速停止 
./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求 
./nginx -s reload 重新加载配置 

6 防火墙

关闭防火墙 
systemctl stop firewalld.service
禁止防火墙开机启动 
systemctl disable firewalld.service
放行端口 
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙 
firewall-cmd --reload

7 把nginx安装成系统服务

  • 创建脚本
    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=/usr/local/nginx/logs/nginx.pid 
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf 
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
ExecReload=/usr/local/nginx/sbin/nginx -s reload 
ExecStop=/usr/local/nginx/sbin/nginx -s stop 
ExecQuit=/usr/local/nginx/sbin/nginx -s quit 
PrivateTmp=true 
 
[Install] 
WantedBy=multi-user.target 
  • 重新加载系统服务
    systemctl daemon-reload

  • 启动服务
    systemctl start nginx.service

  • 设置为 开机自启动
    systemctl enable nginx.service

注意: 设置服务之前先把nginx服务关闭掉 关闭方法 nginx命令关闭或者kill
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

大道至简@EveryDay

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

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

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

打赏作者

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

抵扣说明:

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

余额充值