下载
官方网站:https://nginx.org/en/download.html
Windows下安装
安装
下载后解压(切记不能含有中文路径!!),文件结构如图(我解压的路径就有中文,记得拷贝放置于英文目录下即可!):
启动
两种方法:
1) 直接双击该目录下的"nginx.exe",即可启动nginx服务器;
2) 命令行进入该文件夹,执行start nginx命令,也会直接启动nginx服务器。
验证
开浏览器,输入地址:http://localhost,访问页面,出现如下页面表示访问成功。
Nginx Windows基本操作指令
启动服务:start nginx
退出服务:nginx -s quit
强制关闭服务:nginx -s stop
重载服务:nginx -s reload (重载服务配置文件,类似于重启,服务不会中止)
验证配置文件:nginx -t
使用配置文件:nginx -c "配置文件路径"
使用帮助:nginx -h
Linux下安装
申明:基于CentOS 7系统。
Nginx依赖包
模块依赖性Nginx需要依赖下面3个包
- ssl功能需要 openssl 库 ( 点击下载 )
- gzip模块需要 zlib 库 ( 点击下载 )
- rewrite模块需要 pcre 库 ( 点击下载 )
依赖包安装顺序依次为:openssl、zlib、pcre, 最后安装Nginx包。
安装教程(源码安装)
step 1:下载所需包
openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.12.2.tar.gz
step 2:安装OpenSSL
[root@localhost wcw]# tar -zxvf openssl-fips-2.0.2.tar.gz
[root@localhost wcw]# cd openssl-fips-2.0.2
[root@localhost openssl-fips-2.0.2]# ./config
[root@localhost openssl-fips-2.0.2]# make
[root@localhost openssl-fips-2.0.2]# make install
step 3:安装zlib
[root@localhost wcw]# tar -zxvf zlib-1.2.7.tar.gz
[root@localhost wcw]# cd zlib-1.2.7
[root@localhost zlib-1.2.7]# ./configure
[root@localhost zlib-1.2.7]# make
[root@localhost zlib-1.2.7]# make install
step 4:安装pcre
[root@localhost wcw]# tar -zxvf pcre-8.21.tar.gz
[root@localhost wcw]# cd pcre-8.21
[root@localhost pcre-8.21]# ./configure
[root@localhost pcre-8.21]# make
[root@localhost pcre-8.21]# make install
step 5:安装Nginx
[root@localhost wcw]# tar -zxvf nginx-1.12.2.tar.gz
[root@localhost wcw]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/install/nginx --with-pcre&#