1. 使用命令行安装
如果是在mac下,可以使用brew安装。
2. 源码编译安装
在生产环境下,我们可能需要下载源码编译安装,因为用命令行安装的方式,第一,自定义性不强,第二,可能安装包比较老。
登录到主机环境,这里以ubuntu系统安装目前的nginx稳定版本1.8.0为例。
接下来到官方网站下载nginx的源码包。
# 下载源码包
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
# 解压
$ tar xvf nginx-1.8.0.tar.gz
# 进入目录并生成Makefile文件
$ ./configure \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-file-aio \
--with-http_realip_module \
--without-http_scgi_module \
--without-http_uwsgi_module \
--without-http_fastcgi_module \
上面的./configure命令我是按照自己的需要来定制安装,如果要简单点的话,直接运行./configure
就好了。
关于上面的参数可以使用nginx -V
来查看。
这样就算安装成功。
要启动nginx,可以这样:
$ sudo nginx
如果要停止服务,可以这样:
$ sudo nginx -s reload
完结。