1. 准备工作
安装nginx之前,要先在服务器上安装nginx运行所需要的依赖包
目录选择:一般选择 "/usr/local/"
(1) 安装PCRE库
离线安装包:
https://pan.baidu.com/s/1k_jDkGuMD5XRqDBz5MYhLg
密码:89nj
也可以使用wget在线下载安装包
cd /usr/local/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install
(2) 安装zlib库
离线安装包:
https://pan.baidu.com/s/1198lSj48reV9vvjZjKJpHQ
密码:4nrl 也可以使用wget在线下载安装包
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
(3) 安装openssl
离线安装包:
https://pan.baidu.com/s/1V57vak0Z38fxPe3-JOTsSA
密码:8aig
也可以使用wget在线下载安装包
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
(4)上述依赖包安装完成后,继续安装nginx
离线安装包:
https://pan.baidu.com/s/1AuV0q5qnX7lKoMggOFS5gg
密码:oytn
也可以使用wget在线下载安装包
wget http://nginx.org/download/nginx-1.1.10.tar.gz
tar -zxvf nginx-1.1.10.tar.gz
cd nginx-1.1.10
./configure
make
make install
安装完成后会在 /usr/local/ 下多出一个nginx目录(注意:nginx-1.9.1这个目录解压后的安装包,是个程序包目录,而安装完成nginx后会出现一个nginx目录)
未启动nginx时,进入nginx目录,如下图所示
启动后,nginx目录下会多出几个文件夹,如下图所示
2. 常用的命令
(1)启动命令
第一种方式:
[root@localhost ~]# /usr/local/nginx/sbin/nginx
第二种方式:
[root@localhost ~]# cd /usr/local/nginx/sbin # 先切换到/sbin目录
[root@localhost sbin]# ./nginx
(2) 停止命令
第一种方式:
[root@localhost sbin]# ./nginx -s stop # 先切换到/sbin目录,然后使用该命令
第二种方式:
[root@localhost sbin]# ./nginx -s quit # -s都是采用向 Nginx 发送信号的方式。
(3) 修改nginx配置后,重新加载配置文件
第一种方式:
[root@localhost sbin]# ./nginx -s reload
第二种方式:
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -s reload
(4) 显示帮助信息
[root@localhost sbin]# ./nginx -h
nginx version: nginx/1.9.1
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
[root@localhost sbin]#
(5) 查看nginx是否运行
[root@localhost sbin]# ps -ef|grep nginx
root 3504 1 0 Jul03 ? 00:00:00 nginx: master process ./nginx
nobody 3729 3504 0 Jul03 ? 00:00:00 nginx: worker process
root 6315 2708 0 00:33 pts/0 00:00:00 grep --color=auto nginx
[root@localhost sbin]#
(6)查看nginx监听端口的状态
[root@localhost sbin]# netstat -npa|grep 80|grep nginx
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3504/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3504/nginx: master
[root@localhost sbin]#