1、准备安装
考虑到Nginx在Linux上的运行效率要比Windows高,且目前大多数服务器会选择Linux系统,在此只记录Linux版本编译安装。编译之前需要对安装的系统和软件做简单介绍。截止目前,使用的Linux发型版为Centos7.4,使用的Nginx软件为nginx-1.15.12.tar.gz,使用的gcc为gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ,清单如下:
[root@VM_0_2_centos software]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@VM_0_2_centos software]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
[root@VM_0_2_centos software]# ls -al nginx-1.15.12.tar.gz
-rw-r--r-- 1 root root 1032347 Apr 27 15:55 nginx-1.15.12.tar.gz
2、安装流程
- 为了方便管理和使用,将Nginx安装产生的文件和目录统一到一目录下,所以创建一个目录。
[root@VM_0_2_centos software]# mkdir -p /data/software/nginx
- 解压归档nginx-1.15.12.tar.gz,并且进入该解压路径。
[root@VM_0_2_centos software]# tar zxvf nginx-1.15.12.tar.gz && cd nginx-1.15.12
- 使用configure脚本自动生成makefile文件,configure文件的作用在第一节已经说明。值得一提的是configure脚本支持很多配置指定,如--prefix=<path>、--sbin-path=<path>、--conf-path=<path>等70多种参数,为了文档的流畅性,先不做一一介绍。
#指定安装的路径前缀
[root@VM_0_2_centos software]# ./configure --prefix=/data/software/nginx
#configure脚本经过一系列check(检查,auto目录脚本发挥作用)之后的summary(总结)
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/data/software/nginx"
nginx binary file: "/data/software/nginx/sbin/nginx"
nginx modules path: "/data/software/nginx/modules"
nginx configuration prefix: "/data/software/nginx/conf"
nginx configuration file: "/data/software/nginx/conf/nginx.conf"
nginx pid file: "/data/software/nginx/logs/nginx.pid"
nginx error log file: "/data/software/nginx/logs/error.log"
nginx http access log file: "/data/software/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
- 编译安装,该过程可能会缺少部分环境依赖,大部分问题解决谷歌一下便可以解决。
[root@VM_0_2_centos software]# make && make install
3、启动Nginx服务
以上已经将Nginx编译并且安装到/data/software/nginx目录下,为了以后更好的使用Nginx服务,有必要将生成的文件目录做个介绍:
[root@VM_0_2_centos nginx]# ls -al
total 44
drwxr-xr-x 11 root root 4096 Apr 27 17:59 .
drwxr-xr-x 9 root root 4096 Apr 27 17:21 ..
drwxr-xr-x 2 root root 4096 Apr 27 17:49 conf
drwxr-xr-x 2 root root 4096 Apr 27 17:49 html
drwxr-xr-x 2 root root 4096 Apr 27 17:59 logs
drwxr-xr-x 2 root root 4096 Apr 27 17:49 sbin
- conf Nginx服务运行读取的配置文件,所有的配置文件都存放在这个目录中,其中nginx.conf最为核心。
- html 在第一节以及提过,不做赘述,后续用户任何的静态页面可以存放至此。
- logs 存放日志目录,主要有access.log客户端请求日志文件,error.log处理错误日志文件件。
- sbin 可执行文件。使用该文件启动或者停止Nginx服务。
至此已经对编译生成的目录有初步了解,实际上如果使用Nginx服务,那么每天都是在和这几个目录打交道。接下来将是第一次启动Nginx服务。
[root@VM_0_2_centos nginx]# cd sbin/ && ./nginx
似乎没有任何显示,那么应该查看nginx是否启动
[root@VM_0_2_centos sbin]# ps -ef | grep nginx
root 14928 1 0 18:17 ? 00:00:00 nginx: master process ./nginx
nobody 14929 14928 0 18:17 ? 00:00:00 nginx: worker process
事实上Nginx服务已经启动并且启动了两个进程分别是master process和worker process。后续会对Nginx服务的进程管理做介绍。现在便可以使应curl直接访问。
[root@VM_0_2_centos sbin]# curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
如果查看过Nginx编译生成的目录下html的文件的话,那么你会知道Nginx返回的html文档流正是刚刚介绍过的html目录下的index.html的文档内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)