本文主要是介绍suse 12 编译部署 Nginx,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 编译前准备
- 创建nginx用户
- 下载nginx源码包
- 安装编译环境依赖
- 编译nginx
- 配置nginx为systemctl管理
Linux:~ # cat /etc/os-release
NAME="SLES"
VERSION="12-SP3"
VERSION_ID="12.3"
PRETTY_NAME="SUSE Linux Enterprise Server 12 SP3"
ID="sles"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:12:sp3"
编译前准备
创建nginx用户
Linux:~ # useradd -ms /sbin/nologin nginx
Linux:~ # groupadd nginx
下载nginx源码包
Linux:~ # wget -c http://nginx.org/download/nginx-1.16.0.tar.gz
Linux:~ # tar xf nginx-1.16.0.tar.gz -C /usr/local/
安装编译环境依赖
gcc
环境
Linux:~ # zypper in gcc gcc-c++ make
安装pcre
软件包(使 nginx
支持 http rewrite
模块)
Linux:~ # wget ftp://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
Linux:~ # tar xf pcre-8.44.tar.gz -C /usr/local/
- 如果是Centos发行版,执行
yum install -y pcre pcre-devel
安装zlib
Linux:~ # zypper in libz1 zlib-devel
- 如果是Centos发行版,执行
yum install -y zlib zlib-devel
安装gd
http_image_filter_module
需要gd库
Linux:~ # wget -c https://github.com/libgd/libgd/releases/download/gd-2.3.0/libgd-2.3.0.tar.gz
Linux:~ # tar xf libgd-2.3.0.tar.gz -C /usr/local/
Linux:~ # cd /usr/local/libgd-2.3.0/
Linux:/usr/local/libgd-2.3.0 # ./configure \
--bindir=/usr/sbin \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
--libdir=/usr/lib64 \
--mandir=/usr/share/man &&\
make && \
make install
- 如果是Centos发行版,执行
yum install -y gd gd-devel
安装 openssl
(使 nginx
支持 ssl
)
Linux:~ # zypper in openssl libopenssl-devel
- 如果是Centos发行版,执行
yum install -y openssl openssl-devel
编译nginx
Linux:~ # cd /usr/local/nginx-1.16.0/
Linux:/usr/local/nginx-1.16.0 # ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-pcre=/usr/local/pcre-8.44 \
--with-http_ssl_module \
--with-http_v2_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-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module && \
make && \
make install
配置nginx为systemctl管理
Linux:~ # cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -S reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true[Install]
WantedBy=multi-user.target
EOF
Linux:~ # systemctl daemon-reload
Linux:~ # systemctl enable nginx --now
Linux:~ # ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
Linux:~ # nginx -v
nginx version: nginx/1.16.0
这篇关于suse 12 编译部署 Nginx的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!