centos8(7)下nginx编译安装(附脚本文件)

操作步骤

(整合的脚本文件在最后)

1.下载最新版本的nginx

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


2.解压

tar xf nginx-1.19.0.tar.gz
cd nginx-1.19.0


3. 安装依赖关系包
 

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

4.新建用户

useradd wang -s /sbin/nologin

5.安装

make

 编译安装

make install

6.启动nginx

/usr/local/nginx2/sbin/nginx

7.修改环境变量

echo 'PATH=$PATH:/usr/local/nginx2/sbin/'  >>/etc/bashrc

8.关闭防火墙

service firewalld stop
systemctl  disable firewall # 设置开机不启动

 9.设置nginx可以通过service方式启动

cat  >/usr/lib/systemd/system/nginx.service <<EOF
[Unit]

Description=The nginx HTTP and reverse proxy server

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

[Service]

Type=forking

PIDFile=/usr/local/nginx2/logs/nginx.pid

# Nginx will fail to start if /run/nginx.pid already exists but has the wrong

# SELinux context. This might happen when running nginx -t from the cmdline.

# https://bugzilla.redhat.com/show_bug.cgi?id=1268621

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

ExecStartPre=/usr/local/nginx2/sbin/nginx -t

ExecStart=/usr/local/nginx2/sbin/nginx

ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=mixed

PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

 重新加载

systemctl  daemon-reload

11.修改配置文件

sed -i '/worker_processes/ s/1/2/g' /usr/local/nginx2/conf/nginx.conf

 10.设置nginx开机启动

#启动nginx
service nginx start

systemctl enable nginx.service

 在浏览器输入虚拟机ip地址就可以访问Nginx了,页面代码在/usr/local/nginx2/html,也可以自己修改页面

* 查看nginx是否开启可以看进程和端口号

ps aux|grep nginx 

lsof -i:80 

 

 脚本文件

#!/bin/bash

#download nginx
curl  -O http://nginx.org/download/nginx-1.19.0.tar.gz

#解压nginx
tar  xf  nginx-1.19.0.tar.gz

cd nginx-1.19.0

#安装依赖关系包
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make 
#编译前的配置,安装路径,开启那些功能等配置---》makefile
useradd  wang -s /sbin/nologin
./configure --prefix=/usr/local/nginx4  --with-http_ssl_module --with-stream --user=wang

#编译,其实就是将源码文件编译成二进制文件,默认存放在当前目录下
make
#编译安装,将编译好的二进制文件复制到指定的安装路径
make  install

#启动nginx
/usr/local/nginx4/sbin/nginx


#修改环境变量
echo 'PATH=$PATH:/usr/local/nginx4/sbin/'  >>/etc/bashrc

#关闭防火墙
service firewalld stop
systemctl disable firewalld

#设置nginx可以通过service方式启动
cat  >/usr/lib/systemd/system/nginx.service <<EOF
[Unit]

Description=The nginx HTTP and reverse proxy server

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

[Service]

Type=forking

PIDFile=/usr/local/nginx2/logs/nginx.pid

# Nginx will fail to start if /run/nginx.pid already exists but has the wrong

# SELinux context. This might happen when running nginx -t from the cmdline.

# https://bugzilla.redhat.com/show_bug.cgi?id=1268621

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

ExecStartPre=/usr/local/nginx2/sbin/nginx -t

ExecStart=/usr/local/nginx2/sbin/nginx

ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=mixed

PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

systemctl  daemon-reload
#修改配置文件
sed -i '/worker_processes/ s/1/2/g' /usr/local/nginx2/conf/nginx.conf

#启动nginx
service nginx start

#开机启动nginx
systemctl enable nginx.service

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值