1. 下载 Nginx,官网下载
https://nginx.org/en/download.html
Nginx官网提供了三个类型的版本:
- Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
- Stable version:最新稳定版,生产环境上建议使用的版本
- Legacy versions:遗留的老版本的稳定版
这里我们下载稳定版,由于是要安装到 Linux 服务器上,故下载 tar.gz 的版本。
2. 安装 Nginx
将文件先上传到服务器,再解压到指定目录下
[root@sit-stf-ap01 nginx]# ll
total 788
drwxr-xr-x 6 1001 1001 326 Jan 7 11:59 auto
-rw-r--r-- 1 1001 1001 312251 Nov 16 22:44 CHANGES
-rw-r--r-- 1 1001 1001 476577 Nov 16 22:44 CHANGES.ru
drwxr-xr-x 2 1001 1001 168 Jan 7 14:29 conf
-rwxr-xr-x 1 1001 1001 2590 Nov 16 22:44 configure
drwxr-xr-x 4 1001 1001 72 Jan 7 11:59 contrib
drwxr-xr-x 2 1001 1001 40 Jan 7 11:59 html
-rw-r--r-- 1 1001 1001 1397 Nov 16 22:44 LICENSE
drwxr-xr-x 2 1001 1001 21 Jan 7 11:59 man
-rw-r--r-- 1 1001 1001 49 Nov 16 22:44 README
drwxr-xr-x 9 1001 1001 91 Jan 7 11:59 src
[root@sit-stf-ap01 nginx]# pwd
/home/nginx
进入文件目录,配置 nginx 路径,当出现配置摘要就可以了
[root@sit-stf-ap01 nginx]# ./configure --prefix=/home/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --conf-path=/home/nginx/nginx.conf
checking for OS
+ Linux 3.10.0-1160.25.1.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
image.png
补全 nginx 配置目录
[root@sit-stf-ap01 nginx]# mkdir /var/temp/nginx -p
编译并安装
[root@sit-stf-ap01 nginx]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/home/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
image.png
安装完成后的目录结构是这样的
[root@sit-stf-ap01 nginx]# ll
total 860
drwxr-xr-x 6 1001 1001 326 Jan 7 11:59 auto
-rw-r--r-- 1 1001 1001 312251 Nov 16 22:44 CHANGES
-rw-r--r-- 1 1001 1001 476577 Nov 16 22:44 CHANGES.ru
drwxr-xr-x 2 1001 1001 168 Jan 7 14:29 conf
-rwxr-xr-x 1 1001 1001 2590 Nov 16 22:44 configure
drwxr-xr-x 4 1001 1001 72 Jan 7 11:59 contrib
-rw------- 1 root root 1077 Jan 7 15:03 fastcgi.conf
-rw------- 1 root root 1077 Jan 7 15:03 fastcgi.conf.default
-rw------- 1 root root 1007 Jan 7 15:03 fastcgi_params
-rw------- 1 root root 1007 Jan 7 15:03 fastcgi_params.default
drwxr-xr-x 2 1001 1001 40 Jan 7 11:59 html
-rw------- 1 root root 2837 Jan 7 15:03 koi-utf
-rw------- 1 root root 2223 Jan 7 15:03 koi-win
-rw-r--r-- 1 1001 1001 1397 Nov 16 22:44 LICENSE
-rw------- 1 root root 412 Jan 7 15:02 Makefile
drwxr-xr-x 2 1001 1001 21 Jan 7 11:59 man
-rw------- 1 root root 5231 Jan 7 15:03 mime.types
-rw------- 1 root root 5231 Jan 7 15:03 mime.types.default
-rw------- 1 root root 2666 Jan 7 15:03 nginx.conf
-rw------- 1 root root 2666 Jan 7 15:03 nginx.conf.default
drwx------ 3 root root 174 Jan 7 15:03 objs
-rw-r--r-- 1 1001 1001 49 Nov 16 22:44 README
drwx------ 2 root root 36 Jan 7 15:03 sbin
-rw------- 1 root root 636 Jan 7 15:03 scgi_params
-rw------- 1 root root 636 Jan 7 15:03 scgi_params.default
drwxr-xr-x 9 1001 1001 91 Jan 7 11:59 src
-rw------- 1 root root 664 Jan 7 15:03 uwsgi_params
-rw------- 1 root root 664 Jan 7 15:03 uwsgi_params.default
-rw------- 1 root root 3610 Jan 7 15:03 win-utf
3. 测试是否安装成功
[root@sit-stf-ap01 nginx]# ./sbin/nginx -t
nginx: the configuration file /home/nginx/nginx.conf syntax is ok
nginx: configuration file /home/nginx/nginx.conf test is successful
当执行结果出现 successful 时表示配置安装成功。
4. 启动 Nginx
# 启动 nginx
[root@sit-stf-ap01 nginx]# ./sbin/nginx -c nginx.conf
# 查看进程
[root@sit-stf-ap01 nginx]# ps -ef | grep nginx
root 24557 1 0 15:11 ? 00:00:00 nginx: master process ./sbin/nginx -c nginx.conf
nobody 24558 24557 0 15:11 ? 00:00:00 nginx: worker process
root 24595 11629 0 15:12 pts/1 00:00:00 grep --color=auto nginx
网友评论