目 录CONTENT

文章目录

nginx编译安装

xlong
2024-06-05 / 0 评论 / 0 点赞 / 21 阅读 / 3488 字 / 正在检测是否收录...

ubuntu机器

编译前准备

#移除apt安装的nginx
apt-get remove nginx

# 安装依赖
apt-get install  gcc g++ make build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libgd-dev libxml2 libxml2-dev uuid-dev libssl-dev

# 下载解压源码
wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar xf nginx-1.24.0.tar.gz 
cd nginx-1.24.0/

编译安装

# 编译三板斧
./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-stream_ssl_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-stream --with-stream_ssl_module

make && make install

# 添加nginx 用户和用户组
groupadd nginx
useradd -s /sbin/nologin -g nginx -M nginx

#创建缓存目录
mkdir -pv /var/cache/nginx/client_temp

添加systemd nginx服务

# 创建nginx服务文件
cat > /lib/systemd/system/nginx.service <<'EOF'
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
        
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
        
[Install]
WantedBy=multi-user.target
EOF

启动服务

# 启动服务
systemctl start nginx 
systemctl status  nginx 

#配置开机自启
systemctl enable nginx 

nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf

查看stream是否有stream模块

nginx -V 2>&1 | grep  'stream'

如果没有模块需要源码编译添加 --with-stream 参数。

make: *** No rule to make target 'build', needed by 'default'. Stop.

0

评论区