美文网首页
centos7安装nginx1.18

centos7安装nginx1.18

作者: rosekissyou | 来源:发表于2020-06-24 11:58 被阅读0次

1 nginx必备软件

GCC编译工具 PCRE库 支持正则 zlib库 gzip格式的压缩

openssl开发库,支持https协议以及md5 和 sha1等散列函数

yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel

yum install -y openssl openssl-devel

下载

wget http://nginx.org/download/nginx-1.18.0.tar.gz

tar -zxvf nginx-1.18.0.tar.gz

cd nginx-1.18.0

./configure

这里成功的话会产生即将安装的目录

如果报错的话就要看看是不是上面的组件没有安装

make && make install

2 磁盘目录

默认目录是  /usr/local/nginx

cd sbin

#启动nginx

./nginx

查看nginx是否启动

ps -ef | grep nginx

#如果看到启动成功,接下来加入到bin命令里面 也就是设置全局的nginx命令

cp /usr/local/nginx/sbin/nginx /bin/

开启80端口访问,一般情况下不需要开启,我这边是全新服务器,所以需要自己开启

# 开放80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent 

firewall-cmd --zone=public --add-port=80/udp --permanent

firewall-cmd --reload  # 配置立即生效

# 查看防火墙所有开放的端口

firewall-cmd --zone=public --list-ports

设置开机启动

cd /lib/systemd/system/

vi nginx.service

编辑nginx.service内容如下

[Unit]

Description=nginx service

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

# 设置开机启动

systemctl enable nginx

如果需要关闭开机启动

systemctl disable nginx

 一个常见的错误

Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units.

 直接按照提示执行命令systemctl daemon-reload 即可。

systemctl daemon-reload

相关文章

网友评论

      本文标题:centos7安装nginx1.18

      本文链接:https://www.haomeiwen.com/subject/lyhrfktx.html