CentOS 7 离线安装Nginx

前提

在一些无法联网的内网环境中安装Nginx。

安装脚本

将脚本和所有包放到同一目录中

#!/bin/bash

# 安装zlib
## wget http://mirror.centos.org/centos/7/os/x86_64/Packages/zlib-devel-1.2.7-18.el7.i686.rpm
rpm -ivh zlib-devel-1.2.7-18.el7.x86_64.rpm

# 安装pcre
## wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install

# 安装Nginx
tar zxf nginx-1.17.3.tar.gz
## http://nginx.org/download/nginx-1.17.3.tar.gz

## 配置
cd nginx-1.17.3
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35

## 编译安装
make && make install

## 创建mongodb服务
echo "[Unit]

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

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reopen
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target" > /lib/systemd/system/nginx.service

## 服务启动
systemctl enable nginx.service
systemctl start nginx.service

说明

Nginx的安装目录在/usr/local/nginx
配置文件在/usr/local/nginx/conf/nginx.conf

0%