CentOS7 Nginx服务部署

1、相关依赖软件包

1-1、安装OpenSSL包

[root@dev-nginx soft]# wget https://ftp.openssl.org/source/old/1.1.0/openssl-1.1.0f.tar.gz
[root@dev-nginx soft]# tar -zxvf openssl-1.1.0f.tar.gz -C /usr/local/
[root@dev-nginx soft]# cd /usr/loca/openssl-1.1.0f/
[root@dev-nginx openssl-1.1.0f]# ./config
[root@dev-nginx openssl-1.1.0f]# make && make install

1-2、安装pcre包

[root@dev-nginx soft]# wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
[root@dev-nginx soft]# tar -zxvf pcre-8.40.tar.gz -C /usr/local/
[root@dev-nginx soft]# cd /usr/local/pcre-8.40
[root@dev-nginx pcre-8.40]# ./configure
[root@dev-nginx pcre-8.40]# make && make install

1-3、安装zlib包

[root@dev-nginx soft]# wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
[root@dev-nginx soft]# tar -zxvf zlib-1.2.11.tar.gz -C /usr/local/
[root@dev-nginx soft]# cd /usr/local/zlib-1.2.11
[root@dev-nginx zlib-1.2.11]# ./configure 
[root@dev-nginx zlib-1.2.11]# make && make install

1-4、nginx包

[root@dev-nginx soft]# wget https://nginx.org/download/nginx-1.20.1.tar.gz
2、NG安装
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre-devel
  • 安装Nginx
# 解包
[root@dev-nginx soft]# tar -xvf nginx-1.20.1.tar.gz
# 开始编译安装
[root@dev-nginx soft]# cd nginx-1.20.1/
[root@dev-nginx soft]# ./configure --prefix=/usr/local/nginx-1.20.1 \
--with-http_ssl_module \
--with-openssl=/usr/local/openssl-1.1.0f \
--with-http_stub_status_module \
--with-pcre=/usr/local/pcre-8.40 \
--with-zlib=/usr/local/zlib-1.2.11

Configuration summary
  + using PCRE library: /usr/local/pcre-8.40
  + using OpenSSL library: /usr/local/openssl-1.1.0f
  + using zlib library: /usr/local/zlib-1.2.11

  nginx path prefix: "/usr/local/nginx-1.20.1"
  nginx binary file: "/usr/local/nginx-1.20.1/sbin/nginx"
  nginx modules path: "/usr/local/nginx-1.20.1/modules"
  nginx configuration prefix: "/usr/local/nginx-1.20.1/conf"
  nginx configuration file: "/usr/local/nginx-1.20.1/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.20.1/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.20.1/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.20.1/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

[root@dev-nginx nginx-1.20.1]# make && make install
# 检测Nginx配置文件
[root@dev-nginx nginx-1.20.1] ./sbin/nginx -tc ./config/nginx.conf
nginx: the configuration file /usr/local/nginx-1.20.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.20.1/conf/nginx.conf test is successful
3.将NG服务加入systemctl服务列表使用systemctl管理

/lib/systemd/system目录下新建nginx.service文件,内容如下:

[root@dev-nginx system]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx-1.20.1/logs/nginx.pid	# 文件目录路径根据实现目录配置
ExecStart=/usr/local/nginx-1.20.1/sbin/nginx -c /usr/local/nginx-1.20.1/conf/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /usr/local/nginx-1.20.1/logs/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /usr/local/nginx-1.20.1/logs/nginx.pid)"

[Install]
WantedBy=multi-user.target
[root@dev-nginx system]# systemctl start nginx
[root@dev-nginx system]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-06-01 14:49:45 CST; 6s ago
     Docs: http://nginx.org/en/docs/
  Process: 5720 ExecStart=/usr/local/nginx-1.20.1/sbin/nginx -c /usr/local/nginx-1.20.1/conf/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 5721 (nginx)
   CGroup: /system.slice/nginx.service
           ├─5721 nginx: master process /usr/local/nginx-1.20.1/sbin/nginx -c /usr/local/nginx-1.20.1/con...
           └─5722 nginx: worker process

Jun 01 14:49:45 dev-nginx systemd[1]: Starting nginx - high performance web server...
Jun 01 14:49:45 dev-nginx systemd[1]: Started nginx - high performance web server.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值