Linux

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

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

原文地址:https://www.cnblogs.com/jiqing9006/p/8257427.html