编译安装的nginx使用systemctl管理

 centos7系统编译安装nginx

systemctl stop firewalld && systemctl disable 
  
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config #关闭SELINUX setenfoce 0
setenforce 0 # 临时关闭selinx

1.安装编译环境

yum -y install gcc gcc-c++

2.安装pcre软件包(使nginx支持http rewrite模块)

yum install -y pcre pcre-devel

3.安装openssl-devel(使nginx支持ssl)

yum install -y openssl openssl-devel

4.安装zlib

yum install -y zlib zlib-devel

5.创建用户nginx

useradd -r nginx

6.安装nginx

wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar xf nginx-1.20.0.tar.gz
cd nginx-1.20.0
./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
make && make install

配置文件在 /etc/nginx/nginx.conf
默认网站发布目录 /usr/local/nginx/html

7.创建环境变量

vim /etc/profile.d/nginx.sh

NGINX_HOME=/usr/local/nginx
PATH=$NGINX_HOME/sbin:$PATH
export NGINX_HOME PATH

source /etc/profile.d/nginx.sh

8.启动nginx

mkdir -p /tmp/nginx
nginx

添加systemctl管理

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStartPre=/bin/mkdir /tmp/nginx
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

解析:

ExexStartPre 服务启动前操作

PrivateTmp 开启临时空间  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值