查看当前系统版本是否支持
当前,nginx发布包支持以下Linux操作系统版本:
RHEL/CentOS:
[blockquote]
| Version | Supported Platforms |
[/blockquote]
Debian:
[blockquote]
| Version | Codename | Supported Platforms |
[/blockquote]
Ubuntu:
[blockquote]
| Version | Codename | Supported Platforms |
[/blockquote]
SLES:
[blockquote]
| Version | Supported Platforms |
[/blockquote]
我们可以在命令行输入命令 "cat /etc/os-release" 查看当前操作系统版本,如下所示:
[root@localhost local]# cat /etc/os-release name="Red Hat Enterprise Linux Server"VERSION="7.0 (Maipo)"id="rhel"ID_LIKE="fedora"VERSION_id="7.0"PRETTY_name="Red Hat Enterprise Linux Server 7.0 (Maipo)"ANSI_COLOR="0;31"CPE_name="cpe:/o:redhat:enterprise_linux:7.0:GA:server"HOME_URL="https://www.redhat.com/"BUG_REPORT_URL="https://bugzilla.redhat.com/"REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"REDHAT_BUGZILLA_PRODUCT_VERSION=7.0REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"REDHAT_SUPPORT_PRODUCT_VERSION=7.0
可见,操作系统属于RHEL7.X,符合要求。
下载
可以输入wget http://nginx.org/download/nginx-1.10.2.tar.gz 命令直接从网上获取资源包,也可以自己下载。
我这里直接从官网下载nginx-1.10.2.tar.gz包,并放到/usr/local目录下;
输入tar -zxvf nginx-1.10.2.tar.gz命令解压。
配置
进入解压后的目录:
cd /usr/local/nginx-1.10.2
开始配置,可以配置各种参数以及是否启用某些模块等,,详细配置参数可参考官网,有很详细的说明,
http://nginx.org/en/docs/configure.html
如下,是我的配置:
./configure --prefix=/usr/local/nginx-1.10.2 --conf-path=/usr/local/nginx-1.10.2/nginx.conf --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-mail --with-mail_ssl_module
编译
输入以下命令即可:
make && make install
启动服务
进入sbin目录,输入nginx命令即可,另外重启命令是nginx -s reload
验证服务是否启动
查看进程即可,如下是我的nginx服务进程
root 20646 1 0 11:04 ? 00:00:00 nginx: master process nginxnobody 20647 20646 0 11:04 ? 00:00:00 nginx: worker process
遇到的问题
1、"conf/koi-win" 与"/usr/local/nginx/conf/koi-win" 为同一文件
配置的时候,加上--conf-path参数的配置即可。
2、nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
端口被占用了,修改端口号即可。我这里是有个tomcat的端口配置为80,改成其它的即可。