在Linux环境下离线安装Nginx 1.27,需要提前准备好依赖包和Nginx源码,然后通过编译安装。以下是详细步骤:
使用U盘、SFTP、SCP等方式将文件上传到目标机器,例如放到 /opt/nginx 目录。
# 如果是基于RPM的系统(如CentOS/RHEL)
# 提前下载并安装以下包(示例版本):
rpm -ivh gcc-*.rpm
rpm -ivh make-*.rpm
rpm -ivh glibc-devel-*.rpm
# 如果是基于Debian的系统(如Ubuntu)
# 提前下载并安装以下包:
dpkg -i gcc_*.deb
dpkg -i make_*.deb
dpkg -i build-essential_*.debcd /opt/nginx
tar -zxvf pcre-8.45.tar.gz
tar -zxvf zlib-1.3.1.tar.gz
tar -zxvf openssl-3.0.13.tar.gz # 可选
# 编译安装PCRE
cd pcre-8.45
./configure
make && make install
# 编译安装zlib
cd ../zlib-1.3.1
./configure
make && make install
# 编译安装OpenSSL(可选)
cd ../openssl-3.0.13
./config
make && make installcd /opt/nginx
tar -zxvf nginx-1.27.0.tar.gz
cd nginx-1.27.0./configure
--prefix=/usr/local/nginx
--with-http_ssl_module # 启用SSL(需OpenSSL)
--with-pcre=../pcre-8.45 # 指定PCRE源码路径
--with-zlib=../zlib-1.3.1 # 指定zlib源码路径
--with-openssl=../openssl-3.0.13 # 指定OpenSSL源码路径(可选)make
make install创建文件
/etc/systemd/system/nginx.service:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
TimeoutStopSec=5
KillMode=process
[Install]
WantedBy=multi-user.targetsystemctl daemon-reload
systemctl start nginx
systemctl enable nginxcurl http://localhost# 开放80/443端口(以firewalld为例)
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload通过以上步骤,可以在离线环境中完成Nginx 1.27的安装。