参考博客地址:https://www.cnblogs.com/piscesLoveCc/p/5794926.html
---安装
安装gcc g++的依赖库
ubuntu平台可以使用如下命令。
1
2
|
apt-get install build-essential
apt-get install libtool
|
centeros平台可以使用如下命令。
1
2
3
4
5
6
|
centos平台编译环境使用如下指令
安装make:
yum -y install gcc automake autoconf libtool make
安装g++:
yum install gcc gcc-c++
|
安装 pcre依赖库(http://www.pcre.org/)
1
2
|
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
|
安装 zlib依赖库(http://www.zlib.net)
1
|
apt-get install zlib1g-dev
|
安装 ssl依赖库
1
|
apt-get install openssl
|
安装Nginx(http://nginx.org)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#下载最新版本:
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
#编辑nginx:
make
注意:这里可能会报错,提示“pcre.h No such file or directory”,具体详见:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory
需要安装 libpcre3-dev,命令为:sudo apt-get install libpcre3-dev
#安装nginx:
sudo make install
#启动nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。
#查看nginx进程:
ps -ef|grep nginx
|
Nginx常用命令
启动 Nginx
1
2
3
|
/usr/local/nginx/sbin/nginx
./sbin/nginx
|
停止 Nginx
1
2
3
|
./sbin/nginx -s stop
./sbin/nginx -s quit
|
-s都是采用向 Nginx 发送信号的方式。
Nginx重新加载配置
1
|
./sbin/nginx -s reload
|
指定配置文件
1
|
./sbin/nginx -c /usr/local/nginx/conf/nginx.conf
|
-c表示configuration,指定配置文件
查看 Nginx 版本
有两种可以查看 Nginx 的版本信息的参数。第一种如下:
1
2
3
|
./sbin/nginx -v
nginx: nginx version: nginx/1.0.0
|
另一种显示的是详细的版本信息:
1
2
3
4
5
|
poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built
by
gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
nginx: TLS SNI support enabled
nginx: configure arguments: --with-http_ssl_module --with-openssl=/home/luming/openssl-1.0.0d/
|
检查配置文件是否正确
1
2
3
4
5
|
poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -t
nginx: [alert] could not open error log file: open()
"/usr/local/nginx/logs/error.log"
failed (13: Permission denied)
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax
is
ok
2012/01/09 16:45:09 [emerg] 23898#0: open()
"/usr/local/nginx/logs/nginx.pid"
failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
|
如果出现如上的提示信息,表示没有访问错误日志文件和进程,可以sudo(super user do)一下:
1
2
3
|
poerchant@ubuntu:/usr/local/nginx$ sudo ./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
|
如果显示如上,则表示配置文件正确。否则,会有相关提示。
显示帮助信息
1
|
poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -h
|
或者:
1
|
poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -?
|
--问题
170217、nginx 安装时候报错:make: *** No rule to make target `build', needed by `default'. Stop.
出现此种情况,是linux系统没有安装先决条件
1、GCC——GNU编译器集合(GCC可以使用默认包管理器的仓库(repositories)来安装,包管理器的选择依赖于你使用的Linux发布版本,包管理器有不同的实现:yum是基于Red Hat的发布版本;apt用于Debian和Ubuntu;yast用于SuSE Linux等等。)
RedHat中安装GCC:
yum install gcc
Ubuntu中安装GCC:
apt-get install gcc
2、PCRE库(Nginx编译需要PCRE(Perl Compatible Regular Expression),因为Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法。这里需要安装两个安装包pcre和pcre-devel。第一个安装包提供编译版本的库,而第二个提供开发阶段的头文件和编译项目的源代码,这正是我们需要的理由。)
RedHat中安装PCRE:
yum install pcre pcre-devel
Ubuntu中安装PCRE:
apt-get install libpcre3 libpcre3-dev
3、zlib库(zlib库提供了开发人员的压缩算法,在Nginx的各种模块中需要使用gzip压缩。如同安装PCRE一样,同样需要安装库和它的源代码:zlib和zlib-devel。)
RedHat中安装zlib:
yum install zlib zlib-devel
Ubuntu中安装zlib:
apt-get install zlib1g zlib1g-dev
4、OpenSSL库(在Nginx中,如果服务器提供安全网页时则会用到OpenSSL库,我们需要安装库文件和它的开发安装包(openssl和openssl-devel)。)
RedHat中安装OpenSSL:
yum install openssl openssl-devel
Ubuntu中安装OpenSSL:(注:Ubuntu14.04的仓库中没有发现openssl-dev):
apt-get install openssl openssl-dev
注意:要不关闭防火墙,要不然放不了nginx页面