安装 Nginx 服务

2023-05-16

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(使用前将#替换为@)

安装 Nginx 服务 的相关文章

随机推荐

  • StringPiece谷歌实现

    typedef BasicStringPiece span class token operator lt span std string span class token operator gt span StringPiece span
  • c++正则表达式

    https blog csdn net qq 62309585 article details 126776015 对字符串内容进行匹配的最常见手段就是使用正则表达式 可惜在传统 C 43 43 中正则表达式一直没 有得到语言层面的支持 x
  • c++的坑

    span class token keyword for span span class token punctuation span span class token keyword unsigned span span class to
  • iOS NSFileManager文件管理(沙盒)

    OS因为沙盒机制 所以只能访问通讯录 相册和App内的文件 xff0c 下面就来说说如何进行文件管理 App所产生的数据都存在于自己的沙盒中 xff0c 一般沙盒都有3个文件 xff1a Documents Library和tmp Docu
  • 《卓有成效的工程师》读书笔记

    一 聚焦高杠杆率工作 xff1a 1 使用杠杆率衡量工作成效 xff1a 杠杆率 61 产生的影响 投入的时间 xff0c 即时间投资回报率ROI 不要通过更长的时间去完成更多工作 xff0c 要将有限的时间投入到最有价值的工作上 对大多数
  • 结构体冒泡排序(方法简单,简单易懂。没有改变原本的储存位置,而是借用外部数组输出)

    在做项目实战时想把结构体的冒泡排序当作项目扩展 但在网上搜了原理一时又看不懂 xff08 当时做了接近一天的项目实战 xff0c 属实没心情看 xff09 xff0c 突然想到一个简便的方法 就是将一个数组与结构体数组一一对应 然后用数组来
  • Mac OS-X 10.7 装kerberos小记

    打算将mac作为开发机 xff0c 公司机器间的认证是通过kerberos来搭建的 xff0c mac本身已经安装了kerberos xff0c 但是貌似10 7版本的不好使 xff0c 所以在网上查了一下 xff0c 说是要下载一个Ker
  • MySql 8.0 配置外网访问

    1 登进MySQL之后 mysql span class token operator span uroot span class token operator span p span class token operator span s
  • 有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

    include lt stdio h gt include lt stdlib h gt include lt string h gt 5 有n个人围成一圈 xff0c 顺序排号 从第一个人开始报数 xff08 从1到3报数 xff09 x
  • 为什么memset只能给int数组赋值0或-1,而不支持其他的数字

    span class token keyword int span a span class token punctuation span span class token number 10 span span class token p
  • 【Codeforces】Chloe and the sequence (递归)

    题目链接 题解 将序列写出来可以发现规律 xff0c 1 43 2x 的位置值都是 1 xff0c 2 43 4x 的位置的值都是 2 xff0c 4 43 8x 的位置的数都是 3 xff0c 8 43 16x 的位置的数都是 4 xff
  • VS图像处理(二)——图像打开与反色

    目录 一 打开图像 二 图像反色处理 一 打开图像 void CMFCApplication1Doc OnFileOpen TODO 在此添加命令处理程序代码 打开文件对话框 CFileDialog Ofd true 判断是否确认打开文件
  • mysql 分组查询并统计数量

    转载 xff1a mysql 分组查询并统计数量 桑尼的花园的博客 CSDN博客 mysql分组统计数量
  • ATCODER abc240部分题解

    A 判断两数是否相邻 xff0c 或两数分别为1 xff0c 10 span class token macro property span class token directive hash span span class token
  • PC微信 HOOK 接口 (版本:3.6.0.18)

    现在主要的基本功能已经实现 xff0c 接口如下 xff1a 启动微信 多开微信 使用GBK编码 xff08 易语言 xff09 发送消息模块 发送文本消息 发送图片消息 发送文件消息 发送GIF消息 发送艾特消息 发送名片消息 发送链接消
  • python数据分析(2)

    xff08 1 xff09 创建一个1到10的数组 xff0c 然后逆序输出 xff08 2 xff09 创建一个长度为20的全1数组 xff0c 然后变成一个4 5的二维矩阵并转置 xff08 3 xff09 创建一个3x3x3的随机数组
  • iOS 图像选取器UIImagePickerController

    UIImagePickerController UIImagePickerController可以帮助我们调用摄像头拍照或者希望从相册中选择照片 UIImagePickerController主要属性 span class token co
  • c++ 堆栈信息输出,简单实用

    根据网上大佬的写法魔改了一下 xff0c 把自己的debug系统忽略掉 xff0c 然后只输出到main就结束 同时传入了log文件stream来记录log void TraceStack std ofstream amp ofs stat
  • 腾讯云ECS服务器架载“看了都想..."的.NET

    根据1元的学生抢购 xff0c 大家可是赚大了 xff01 光会抢不会配咋行呢 xff1f 服务器到手 xff1a 配置Web xff08 IIS xff09 服务器 xff1a Windows下最常用的网页服务器是自带的IIS xff0c
  • 安装 Nginx 服务

    1 准备安装 考虑到Nginx在Linux上的运行效率要比Windows高 xff0c 且目前大多数服务器会选择Linux系统 xff0c 在此只记录Linux版本编译安装 编译之前需要对安装的系统和软件做简单介绍 截止目前 xff0c 使