美文网首页
nginx 在 CentOS 中的源码编译与安装以及负载均衡配置

nginx 在 CentOS 中的源码编译与安装以及负载均衡配置

作者: Mr包 | 来源:发表于2023-05-04 09:17 被阅读0次

  • 下载 nginx 源码
  • 安装 nginx 编译安装 依赖的工具包
  • nginx 编译的配置
  • nginx 安装
  • nginx 注册服务

1. 下载 nginx 源码包 下载地址

选择linux下的版本
//可以用 wget 命令直接下载 -P 可以直接指定下载目录
wget http://nginx.org/download/nginx-1.11.8.tar.gz -P /home/my/nginx 

2. 安装 nginx 编译安装 依赖的工具包

  • 安装依赖的工具包
yum install gcc gcc-c++ autoconf automake
yum install zlib zlib-devel openssl openssl-devel  pcre-devel
  • 把 nginx 解压到指定的目录
tar -zxvf nginx-1.11.8.tar.gz

进入解压后台的目录

cd nginx-1.11.8

3. nginx 编译的配置

./configure \  
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \    
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_realip_module \
--with-http_sub_module
--with-http_dav_module
--with-upload-module

--sbin-path=/usr/sbin/nginx 需要注意此配置,此配置是指定 nginx 启动程序放置目录
与下发服务配置启动指令强相关,可以不配置此项,sbin 的默认路径一般是 /usr/local/nginx/sbin/nginx

4. nginx 安装

make && make install

5. 注册服务

vim /etc/systemd/system/nginx.service

[Unit]
Description=nginx 
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/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s hup $mainpid
ExecStop=/bin/kill -s quit $mainpid
PrivateTmp=true

[Install]
WantedBy=multi-user.target

相关文章

网友评论

      本文标题:nginx 在 CentOS 中的源码编译与安装以及负载均衡配置

      本文链接:https://www.haomeiwen.com/subject/beagvttx.html