Nginx的编译安装

nginx的编译安装

服务器信息:centos7
安装步骤:

  1. 下载安装nginx源码包
curl -O http://nginx.org/download/nginx-1.17.8.tar.gz
  1. 安装依赖关系包
yum install  gcc  pcre-devel  openssl-devel  -y
  1. 解压
  2. 进入解压后的目录
tar xf nginx-1.17.8.tar.gz
cd nginx-1.17.8
  1. 相关配置
  2. 编译然后再安装
./configure --prefix=/usr/local/nginx2   --with-http_realip_module  --with-http_ssl_module  --with-pcre

make && make install
  1. 启动和设置开机启动 ,加权限
/usr/local/nginx2/sbin/nginx
echo "/usr/local/nginx2/sbin/nginx"  >>/etc/rc.local
chmod +x /etc/rc.d/rc.local
  1. 添加环境变量
PATH=$PATH:/usr/local/nginx2/sbin
echo "PATH=$PATH:/usr/local/nginx2/sbin"  >>/etc/bashrc
  1. 关闭防火墙
service firewalld stop
systemctl disable firewalld
  1. 启动nginx服务
cd /etc/local/nginx2/sbin 
./nginx
  1. 编译安装的不能使用systemctl enable nginx去设置开机启动,因为没有相关的脚本和配置,编写脚本
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx9/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /usr/local/nginx9/logs/nginx.pid
ExecStartPre=/usr/local/nginx9/sbin/nginx -t
ExecStart=/usr/local/nginx9/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=mixed
PrivateTmp=true

[Install]
WantedBy=multi-user.target

  1. 验证
nginx -s stop
lsof -i:80
systemctl start nginx
lsof -i:80
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nginx   69933 root    8u  IPv4 17909556      0t0  TCP *:http (LISTEN)
nginx   69934 lihu    8u  IPv4 17909556      0t0  TCP *:http (LISTEN)
systemctl stop nginx
 lsof -i:80
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值