Nginx入门一:安装Nginx

一.简单安装

linux环境准备Centos7

yum install epel-release -y
  
yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake

yum -y install wget httpd-tools vim

yum list all | grep nginx

yum install nginx -y

# 列出包里的所有文件
rpm -ql nginx

rpm -ql nginx | grep bin

二.编译安装

1. 登录nginx官网下载源码

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

2. 将包传送到/data目录,并解压

tar zxvf /data/nginx-1.20.0.tar.gz

3.进入/data/nginx-1.20.0目录,执行一下命令安装

./configure --prefix=/usr/local/nginx

4.提示

checking for OS
 + Linux 3.10.0-862.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

5.找不到编译器,使用以下命令进行安装:

yum -y install gcc gcc-c++ autoconf automake make
yum install pcre -y
yum install pcre-devel -y 
yum install -y zlib
yum install -y zlib-devel

6. 再次进入/data/nginx-1.20.0目录,执行一下命令安装

./configure --prefix=/usr/local/nginx

7.成功过,执行编译命令编译

make && make install

 

 编译成功。

三.给nginx增加系统服务

1. 新建Nginx文件/lib/systemd/system/

vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target


[Service]
Type=forking
# 路径对应安装路径
Type=forking
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
PrivateTmp=true

[Install]
WantedBy=multi-user.target

2. 修改权限并且开机启动

chmod 755 /lib/systemd/system/nginx.service

3.执行命令

systemctl start nginx.service    启动nginx

systemctl stop nginx.service     结束nginx

systemctl restart nginx.service  重启nginx

systemctl status nginx.service    查看nginx

systemctl enabled nginx.service    加入开启启动

 

posted @ 2021-05-18 09:46  社会主义搬矿人  阅读(159)  评论(0编辑  收藏  举报