linux 安装nginx

1.下载

打开nginx官网
http://nginx.org/en/download.html  下载稳定版

可以下载后上装到服务器,也可以直接命令下载

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

2.安装依赖

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

3.编译安装

解压安装文件

tar -zxvf nginx-1.18.0.tar.gz

解压后进入nginx目录

cd nginx-1.18.0

进入解压后目录执行编译,编译后会出现 Makefile 文件(支持ssl)

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre

执行make命令

make

在执行 make install 进行安装

make install

4.启动

进入实际安装目录,看看,并在其sbin目录下执行启动nginx(默认安装路径 /usr/local/)

cd /usr/local/nginx/

进入 sbin 目录启动

./nginx

启动后 通过ip进行访问出现,启动成功

5.相关命令

1、启动nginx
./nginx

2、查看启动状态
ps -ef|grep nginx

3、杀死进程(找到master的进程)
nginx -s stop
或者(
kill -TERM PID 
或者 kill -INT PID
或者 kill -9 PID
)

4、重新启动
./nginx -t
-c 指定配置文件
或者 nginx -s reopen

5、重载配置
./nginx -s reload

6、查看版本
./nginx -v  查看版本

在 /etc/init.d 把nginx服务添加为系统服务后可使用

service nginx start #启动
service nginx stop #停止
service nginx reload #重载服务
service nginx restart #重启

6.把nginx服务添加为系统服务

在 /etc/init.d/下创建名为nginx的启动脚本(下载路径:https://download.csdn.net/download/CMEguagua/15563432

#!/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

保存。

注意,保存一定要保存成UNIX格式(notepad++:编辑–文档格式转换–转为UNIX格式),否则会如下报错的

设置执行权限:chmod +x /etc/init.d/nginx
注册成服务:chkconfig -add nginx
设置开机启动:chkconfig nginx on

之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值