Linux - Nginx安装

本文详细介绍Nginx从解压、编译到安装的全过程,并配置环境变量,实现任意位置操作Nginx。此外还提供了Nginx的启动、停止方法及Service脚本配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.复制解压。

[root@localhost ~]# mv /opt/nginx-1.13.8.tar.gz /usr/local/src
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar -zxvf nginx-1.13.8.tar.gz 

2.编译安装

[root@localhost src]# cd nginx-1.13.8
[root@localhost nginx-1.13.8]# ./configure --prefix=/usr/local/nginx 

如果没有安装pcre、pcre-devel、openssl、zlib都安装一下。

提示

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library
[root@localhost nginx-1.13.8]# ./configure --prefix=/usr/local/nginx  --with-openssl=/usr/local/openssl

调整,增加openssl位置绑定。

3.安装

make && make install

4.检测是否安装成功

ps -ef |grep nginx

ps 查看进程。
-e 显示所有进程。
-f 全格式。

[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps -ef |grep nginx
root       9334      1  0 18:38 ?        00:00:00 nginx: master process ./nginx
nobody     9335   9334  0 18:38 ?        00:00:00 nginx: worker process
root       9341   4092  0 18:38 pts/1    00:00:00 grep nginx

422101-20180110104343863-547950507.png

5.配置环境变量

[root@localhost sbin]# vim /etc/profile
PATH=$PATH:/usr/local/nginx/sbin
export PATH
[root@localhost sbin]# source /etc/profile

这个时候就可以在任何地方操作nginx了。

[root@localhost local]# nginx -s stop
[root@localhost local]# ps -ef |grep nginx
root       9370   4092  0 18:46 pts/1    00:00:00 grep nginx

6.nginx关闭

[root@localhost local]# nginx -s stop

其他的方式

kill -quit 主进程号
kill -term 主进程号
pkill -9 nginx

7.配置service脚本

[root@localhost nginx]# vim nginx
#! /bin/bash
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
case "$1" in
    start)
        /usr/local/nginx/sbin/nginx
        ;;  
    stop)
        /usr/bin/killall -s QUIT nginx
        ;;  
    restart)
        $0 stop
        $0 start
        ;;  
    reload)
        /usr/bin/killall -s HUP nginx
        ;;  
    *)  
        echo "Usage:$0 {start|stop|restart|reload}"
        exit 1
esac
exit 0

[root@localhost nginx]# cp /usr/local/nginx/nginx /etc/init.d
[root@localhost nginx]# chmod a+x /etc/init.d/nginx 
[root@localhost nginx]# chkconfig --add nginx
[root@localhost nginx]# chkconfig --level 2345 nginx on
[root@localhost nginx]# service nginx stop
[root@localhost nginx]# ps -ef |grep nginx
root       9532   4092  0 19:23 pts/1    00:00:00 grep nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值