近年来,nginx服务器程序由于负载均衡、反向代理、适于高并发的特性,获得越来越多互联网企业的青睐。在此为大家奉上nginx的安装过程,以供参考。

一、安装nginx

1.安装gcc\g++库

root@ubuntu:~# apt-get install build-essential
root@ubuntu:~# apt-get install libtool

2.安装prce库

root@ubuntu:~# apt-get install libpcre3 libpcre3-dev

3.安装zlib依赖库

root@ubuntu:~# apt-get install zlib1g-dev

4.安装ssl依赖库

root@ubuntu:~# apt-get install openssl

5.切换到普通用户dream361

dream361@ubuntu:~$ pwd
/home/dream361/

6.解压nginx源码包

dream361@ubuntu:~$ tar xvf Downloads/nginx-1.10.3.tar.gz

7.进入到nginx目录

dream361@ubuntu:~$ ./configure --prefix=/usr/local/nginx

8. #编译 make  # 安装 sudo make  install #

9.启动nginx

dream361@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf


二、nginx常用命令

启动

dream361@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx

停止

dream361@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx -s stop

重新加载

dream361@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx -s reload

指定配置文件

dream361@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

查看版本

dream361@ubuntu:~$ /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.10.3

检查配置文件是否正确

dream361@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

显示帮助信息

dream361@ubuntu:~$ /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.10.3
Usage: nginx [-?hvVtTq] [-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
-T : test configuration, dump it 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