Nginx源码安装(Linux)

1.下载nginx:

进入下载页面http://nginx.org/en/download.html,获取下载地址:http://nginx.org/download/nginx-1.14.2.tar.gz

wget http://nginx.org/download/nginx-1.14.2.tar.gz

 

2.解压安装包

tar -xvf nginx-1.14.2.tar.gz

3.编译

cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

问题:编译可能发报错,nginx需要zlib,pcre,openssl 支持 ,安装即可

yum install -y zlib
yum install -y openssl openssl-devel
yum install -y pcre pcre-devel

如果想安装最新的版本,可以到对应的官网下载安装

zlib:http://zlib.net/

pcre:http://www.pcre.org/

openssl:https://www.openssl.org/source/

安装过程很简单,直接常规安装即可

./configure && make && make install

 

4. 添加nginx运行用户

groupadd www
useradd -g www -s /sbin/nologin www

启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

5.设置服务脚本

把下面的shell脚本保存成文件名为 nginx ,添加到 /etc/init.d 目录下

#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx         # 根据安装目录自定义设置
conf=/usr/local/nginx/conf/nginx.conf     # 根据安装目录自定义设置

case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

nginx的原始命令行管理如下:

验证配置是否正确: nginx -t

查看Nginx的版本号:nginx -V

启动Nginx:nginx -c "nginx 配置文件地址"

快速停止或关闭Nginx:nginx -s stop

正常停止或关闭Nginx:nginx -s quit

配置文件修改重装载命令:nginx -s reload

服务启动命令

service start|restart|reload|stop|test|show

6. 设置开机启动

chkconfig --add nginx  #添加服务进开机启动
chkconfig nginx on     #设置成开机启动
chkconfig --list nginx # 查看开机启动状态

 

7.添加新的nginx模块

进入nginx源码模块,重新编译,然后make,把objs中的ngnix文件替换掉原来sbin/nginx,重启nginx

cd nginx-1.14.2

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module 

make

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginxbak

cp objs/nginx /usr/local/nginx/sbin/nginx


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值