查看當前系統版本是否支持
當前,nginx發布包支持以下Linux操作系統版本:
RHEL/CentOS:
Version
Supported Platforms
5.x
x86_64, i386
6.x
x86_64, i386
7.x
x86_64, ppc64le
Debian:
Version
Codename
Supported Platforms
7.x
wheezy
x86_64, i386
8.x
jessie
x86_64, i386
Ubuntu:
Version
Codename
Supported Platforms
12.04
precise
x86_64, i386
14.04
trusty
x86_64, i386, aarch64/arm64
16.04
xenial
x86_64, i386, ppc64el
SLES:
Version
Supported Platforms
12
x86_64
我們可以在命令行輸入命令 "cat /etc/os-release" 查看當前操作系統版本,如下所示:
[[email?protected] 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.0
REDHAT_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
開始配置,可以配置各種參數以及是否啟用某些模塊等,,詳細配置參數可參考官網,有很詳細的說明,
如下,是我的配置:
./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 nginx
nobody?? 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,改成其它的即可。