系统只安装了基本系统
先创建用于Nginx运行的用户和组:
groupadd www
useradd -g www www
cd 到nginx源码根目录下,运行
./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module
报以下错误:
./configure: error: C compiler gcc is not found
原因是没有安装gcc编译器,运行yum install gcc 安装gcc,会下载以下package:
gcc, cpp, glibc-devel, glibc-headers, kernel-headers, libgomp,大约12M左右。
再次运行./configure命令,还不能安装,出现以下错误:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
以为没有安装pcre,就运行了yum install pcre命令,系统提示已安装,百度了下,好象漏了个pcre-devel没装,运行yum install pcre-devel 后,该错误消失了。
但再运行./configure报另外一个错误:
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
估计是ssl的扩展没有装,运行yum install openssl-devel安装该库
这时运行./configure没有报错了。
接着运行make
make install
安装成功!
因为我是装在虚拟机里的,在虚拟机里可以访问到nginx服务,但在虚拟机外就无法访问了,原因是系统有防火墙,关掉就可以了。
关闭防火墙命令:service iptables stop(立刻生效) 或 chkconfig iptables off(重启才能生效)
编译时未指定路径,nginx默认是安装在 /usr/local/nginx/ 目录下。
启动nginx方法:/usr/local/nginx/sbin/nginx
关闭nginx方法:/usr/local/nginx/sbin/nginx -s stop ,要看详细的运行控制参数用 -h 参数即可。
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