Linux安装Nginx

# 1、安装gcc
gcc -v #查看gcc版本
yum -y install gcc #安装命令
# 2、pcre、pcre-devel安装
yum install -y pcre pcre-devel
# 3、zlib安装
yum install -y zlib zlib-devel
# 4、安装openssl
yum install -y openssl openssl-devel
# 5、下载nginx安装包
cd /home/
wget http://nginx.org/download/nginx-1.9.9.tar.gz  
tar -zxvf  nginx-1.9.9.tar.gz 
# 6、切换到cd /home/nginx-1.9.9/下面
./configure
make
make instal
# 7、启动。切换目录到/usr/local/nginx/sbin
./nginx
ps -ef | grep nginx #查看nginx服务是否启动成功
# 8、访问nginx
http://宿主ip:80

无法访问nginx的话 放开端口
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload

# PS:配置开机自启
vim /usr/lib/systemd/system/nginx.service #编写service脚本 将以下内容负复制粘贴进去

[Unit]
Description=nginx
After=network.target
    
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
    
[Install]
WantedBy=multi-user.target
#设置开机启动
systemctl enable nginx

 

posted @ 2021-12-31 11:19  云村的王子  阅读(36)  评论(0编辑  收藏  举报