Nginx编译安装centos7

1.安装依赖
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel


2.下载稳定版nginx
nginx.org


3.创建nginx管理用户
useradd nginx -s /sbin/nologin -M


4.解压到/usr/local/src,进入目录,编译

1./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.16.0/ --with-http_ssl_module --with-http_stub_status_module

(2)make && make install

5.创建目录,创建软链

mkdir /data/service
ln -s /usr/local/nginx-1.16.0/ /data/service/nginx

  1. 创建开机启动
1)vim /usr/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
PIDFile=/usr/local/nginx-1.16.0/logs/nginx.pid
ExecStartPre=/usr/local/nginx-1.16.0/sbin/nginx -t -c /usr/local/nginx-1.16.0/conf/nginx.conf
ExecStart=/usr/local/nginx-1.16.0/sbin/nginx -c /usr/local/nginx-1.16.0/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

(2)systemctl enable nginx.service
systemctl start nginx.service
注:如果修改了systemctl文件,需要重载
执行systemctl daemon-reload

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值