前提
在一些无法联网的内网环境中安装Nginx。
CentOS 7系统安装的时候勾选安装环境,如果没有安装可以挂载系统光盘使用
sudo yum groupinstall -y Development Tools
下载zlib、pcre和nginx复制到系统目录中
pcre-8.35.tar.gz 下载地址:
http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gzzlib-devel-1.2.7-18.el7.x86_64.rpm 下载地址:
http://mirror.centos.org/centos/7/os/x86_64/Packages/zlib-devel-1.2.7-18.el7.i686.rpmnginx-1.17.3.tar.gz 下载地址:
http://nginx.org/download/nginx-1.17.3.tar.gz
安装脚本
将脚本和所有包放到同一目录中
#!/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