JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

源码安装nginx1.21.6

wys521 2024-09-24 23:12:23 精选教程 32 ℃ 0 评论
#!/bin/bash

# 1. yum方式安装依赖包
yum install -y gcc gcc-c++ autoconf automake make pcre pcre-devel zlib zlib-devel openssl openssl-devel
tar -zxvf nginx-1.21.6.tar.gz

# 2. 增加用户nginx
useradd -s /sbin/nologin -M nginx

# 3. 编译安装
cd nginx-1.21.6/
# --with-debug 非生产环境使用   nginx配置文件需要指定  error_log /var/log/nginx/error.log debug;
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-stream
make && make install

# 4. 增加环境变量
cat >> /etc/profile << EOF
# NGINX
export NGINX_HOME=/usr/local/nginx
export PATH=\$PATH:\$NGINX_HOME/sbin
EOF
. /etc/profile

# 5. 增加systemd服务
cat > /lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

# 6. 加载并启动nginx服务
systemctl daemon-reload
# 设置自启动服务
systemctl enable nginx
# 启动nginx服务
systemctl start nginx
# 检查nginx服务
systemctl status nginx

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表