Centos7源码安装nginx并使用systemctl管理
  p0VZPbB9Xio1 2023年11月02日 53 0

1.安装nginx所需依赖包

yum -y install gcc openssl-devel pcre-devel zlib-devel make libxml2 libxml2-dev libxslt-dev libxslt-devel libxslt pcre-devel openssl openssl-devel gd-devel perl perl-devel perl-ExtUtils-Embed geoip geoip-devel bzip2 bzip2-devel curl-devel openldap-devel  readline-devel

2.上传nginx的安装包至/data目录

tar -zxvf nginx-1.18.0.tar.gz -C /data

 

3.指定安装目录与安装

cd nginx-1.18.0

./configure --prefix=/data/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module

4.编译 

make && make install

5.将nginx纳入系统服务

vim /etc/systemd/system/nginx.service

[Unit]

Description=nginx

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/data/nginx/logs/nginx.pid 

ExecStartPre=/usr/bin/rm -f /data/nginx/logs/nginx.pid

ExecStartPre=/data/nginx/sbin/nginx -t

ExecStart=/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=process

PrivateTmp=true

[Install]

WantedBy=multi-user.target

6.服务控制选项

systemctl daemon-reload        # 重载配置

systemctl start nginx          #启动服务

systemctl enable nginx.service   # 开机自启

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
p0VZPbB9Xio1