Ubuntu 16.04LTS安装Nginx

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。

安装Nginx依赖库

安装gcc g++的依赖库

apt-get install build-essential
apt-get install libtool

安装 pcre依赖库

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev 

安装 zlib依赖库

apt-get install zlib1g-dev

安装 ssl依赖库

apt-get install openssl

安装Nginx

下载最新版本

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

解压,编译

tar -zxvf nginx-1.11.3.tar.gz
cd nginx-1.11.3
./configure --prefix=/usr/local/nginx 
make
sudo make install

启动nginx

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ps -ef|grep nginx
root      7797  3211  0 09:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    7798  7797  0 09:43 ?        00:00:00 nginx: worker process
ysl       7804  4913  0 09:44 pts/1    00:00:00 grep --color=auto nginx

Nginx常用命令

启动 Nginx

/usr/local/nginx/sbin/nginx

停止 Nginx

./sbin/nginx -s stop
./sbin/nginx -s quit

Nginx重新加载配置

./sbin/nginx -s reload

指定配置文件

./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

查看 Nginx 版本

./sbin/nginx -v
nginx version: nginx/1.11.3
sudo /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.11.3
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 
configure arguments: --prefix=/usr/local/nginx

检查配置文件是否正确

 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

显示帮助信息

sudo /usr/local/nginx/sbin/nginx -h

ginx version: nginx/1.11.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
posted @ 2018-02-12 09:58  木易森林  阅读(340)  评论(0编辑  收藏  举报