Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。本文是nginx-1.16.1版本为演示版,主要是nginx服务的安装、配置和启动。
1、下载nginx1.1.6.1服务
手动下载访问http://nginx.org/download/地址,下载所需要的nginx版本。 ?
使用wget命令,下载nginx服务,执行wget http://nginx.org/download/nginx-1.16.1.tar.gz命令。
1 | wget?http: //nginx .org /download/nginx-1 .16.1. tar .gz |
2、解压nginx压缩包
解压nginx-1.16.1.tar.gz压缩包文件,使用tar -xvf nginx-1.16.1.tar.gz命令。
1 2 3 4 5 6 7 8 | [root@VM-0-4-centos?home] #?tar?-xvf?nginx-1.16.1.tar.gz? nginx-1.16.1/ nginx-1.16.1 /auto/ nginx-1.16.1 /conf/ ... nginx-1.16.1 /auto/cc/sunc [root@VM-0-4-centos?home] #?ls nginx-1.16.1??nginx-1.16.1. tar .gz |
3、移动nginx服务
将nginx服务,将解压的nginx-1.16.1目录,移动到/usr/local/nginx目录。
1 2 3 | [root@VM-0-4-centos?home] #?mv?nginx-1.16.1?/usr/local/nginx [root@VM-0-4-centos?home] #?cd?/usr/local/nginx/ [root@VM-0-4-centos?home] #?ll |
4、安装相关组件
分别安装gcc-c++包、pcre包、zlib包等,有些系统自动可以跳过该步骤。
1)安装gcc-c++编译器?安装pcre包?安装zlib包
1 2 | [root@VM-0-4-centos?nginx] #?yum?install?gcc-c++ [root@VM-0-4-centos?nginx]#?yum?install?-y?openssl?openssl-devel?pcre?pcre-devel??zlib?zlib-devel |
5、编译nginx
编译nginx服务,在nginx服务根目录下,执行./configure命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@VM-0-2-centos?nginx] #?./configure? checking? for ?OS ? +?Linux?3.10.0-1160.45.1.el7.x86_64?x86_64 checking? for ?C?compiler?...?found ? +?using?GNU?C?compiler ... Configuration?summary ?? +?using?system?PCRE?library ?? +?OpenSSL?library?is?not?used ?? +?using?system?zlib?library ?? nginx?path?prefix:? "/usr/local/nginx" ?? nginx?binary? file :?" /usr/local/nginx/sbi ... |
6、安装nginx
安装nginx服务,在nginx服务根目录下,执行make && make install命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@VM-0-2-centos?nginx] #?make?&&?make?install make ?-f?objs /Makefile make [1]:?Entering?directory?` /usr/local/nginx ' cc?-c?-pipe??-O?-W?-Wall?-Wpointer-arith?-Wno-unused-parameter?-Werror?-g??-I?src /core ?-I?src /event ?-I?src /event/modules ?-I?src /os/unix ?-I?objs?\ -o?objs /src/core/nginx .o?\ src /core/nginx .c ... cp ?objs /nginx ?'/usr/local/nginx/sbin/nginx' test ?-d? '/usr/local/nginx/conf' ?\ ||? mkdir ?-p? '/usr/local/nginx/conf' cp ?conf /koi-win ?'/usr/local/nginx/conf' cp :?‘conf /koi-win ’?and?‘ /usr/local/nginx/conf/koi-win ’?are?the?same? file make [1]:?***?[ install ]?Error?1 make [1]:?Leaving?directory?` /usr/local/nginx ' make :?***?[ install ]?Error?2 |
注意:忽略make错误,nginx能够正常启动即可(这是由于文件解压目录和编译目录是同一文件夹导致,习惯而已,目前看来没有什么影响,忽略make错误)。
7、nginx启动
启动nginx并指定配置文件,使用./sbin/nginx -c /usr/local/nginx/conf/nginx.conf命令。
1 2 3 | [root@VM-0-2-centos?nginx] #?./sbin/nginx?-c?/usr/local/nginx/conf/nginx.conf? nginx:?[alert]?could?not? open ?error?log? file :? open ()? "/usr/local/nginx/logs/error.log" ?failed?(2:?No?such? file ?or?directory) 2022 /01/17 ?13:55:26?[emerg]?30840 #0:?open()?"/usr/local/nginx/logs/access.log"?failed?(2:?No?such?file?or?directory) |
上述错误,需要创建logs目录,执行mkdir logs命令,再重新执行上述命令即可。
1 2 | [root@VM-0-2-centos?nginx] #?mkdir?logs [root@VM-0-2-centos?nginx] #?./sbin/nginx?-c?/usr/local/nginx/conf/nginx.conf |
访问服务器IP,显示如下界面,则表示nginx服务启动成功。
|