以下是在 CentOS 7 上安装 Nginx 1.23.4 并支持 stream、ssl、zip 的步骤:

  1. 创建用户和用户组:
sudo groupadd -r www
sudo useradd -r -g www -s /sbin/nologin -d /var/www/html www
  1. 安装依赖项:
sudo yum install -y gcc automake autoconf libtool make zlib-devel openssl-devel pcre-devel
  1. 下载 Nginx 1.23.4 源代码:
wget https://nginx.org/download/nginx-1.23.4.tar.gz
tar -zxvf nginx-1.23.4.tar.gz
cd nginx-1.23.4
  1. 编译安装 Nginx:
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-stream \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre \
--with-zlib \
--with-openssl
make
sudo make install
  1. 配置 Nginx:
sudo vi /usr/local/nginx/conf/nginx.conf

在 'http' 段添加以下配置:

stream {
    include /usr/local/nginx/conf/stream/*.conf;
}

创建 'stream' 文件夹:

sudo mkdir /usr/local/nginx/conf/stream

在 'stream' 文件夹下创建配置文件 'stream.conf':

sudo vi /usr/local/nginx/conf/stream/stream.conf

添加以下内容:

server {
    listen 12345;
    proxy_pass 127.0.0.1:54321;
}
  1. 测试 Nginx 配置是否正确:
sudo /usr/local/nginx/sbin/nginx -t

如果返回 'nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful',说明配置正确。

  1. 启动 Nginx:
sudo /usr/local/nginx/sbin/nginx
  1. 验证 Nginx 是否正常运行:
sudo netstat -tlnp | grep nginx

如果看到以下结果,说明 Nginx 正常运行:

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12345/nginx: master
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      12345/nginx: master
tcp        0      0 127.0.0.1:12345         0.0.0.0:*               LISTEN      12345/nginx: master

至此,Nginx 1.23.4 已经成功安装并支持 stream、ssl、zip。

CentOS 7 安装 Nginx 1.23.4:支持 Stream、SSL、Zip 部署

原文地址: https://www.cveoy.top/t/topic/nvxE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录