记录一下 Linux(CentOS7) 下 Nginx 安装过程

一、准备工作

版本说明:

  • Linux版本:CentOS 7 64位
  • Nginx版本:nginx-1.20.0

1. 下载安装文件

采用源码包方式安装,当然使用 yum 方式安装也可以,此处使用源码包安装。

进入目录(个人习惯/usr/local),下载安装文件,如果云服务器下载速度过慢也可本地下载后上传。

cd /usr/local
wget http://nginx.org/download/nginx-1.20.0.tar.gz

2. 安装Nginx所需要的依赖

# 安装gcc、gcc-c++
yum -y install gcc
yum -y install gcc-c++ # 安装pcre 、zilb
yum -y install pcre*
yum -y install zlib* # 安装openssl(若需要支持 https 协议)
yum -y install openssl
yum -y install openssl-devel

二、安装及配置Nginx

1. 安装Nginx

1、解压安装包。

tar -zxvf nginx-1.20.0.tar.gz

2、为编译安装做准备,进入解压目录。

cd nginx-1.20.0

3、为编译安装做准备。

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre

注:

--prefix:设置安装路径。

--with-http_stub_status_module:支持nginx状态查询。

--with-http_ssl_module:支持https。

--with-pcre:为了支持rewrite重写功能,必须制定pcre。

4、编译安装。

make && make install

5、指定配置文件启动 Nginx。

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

在浏览器访问 ip,看到如下信息则安装成功。

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com. Thank you for using nginx.

2. 一些命令

修改自己的配置之后,验证配置是否正确,重启 Nginx 命令

# 进入目录
cd /usr/local/nginx/sbin # 验证配置是否正确
./nginx -t
# 如果看到如下内容, 那么配置正确, 可以重启Nginx
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful # 重启Nginx, 之后就可以通过域名访问了, 哈哈
./nginx -s reload

3. Nginx开机自启

# 新建文件
vim /lib/systemd/system/nginx.service # 添加内容
[Unit]
Description=nginx.server
After=network.target [Service]
Type=forking
PIDFILE=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecRepload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true [Install]
WantedBy=multi-user.target

然后使用 systemctl enable nginx.service 开启 nginx 开机自启,重启 CentOS 查看效果。

# 启动nginx服务
systemctl start nginx.service # 停止nginx服务
systemctl stop nginx.service # 重启nginx服务
systemctl restart nginx.service # 查看nginx服务当前状态
systemctl status nginx.service # 设置nginx服务开机自启动
systemctl enable nginx.service # 停止nginx服务开机自启动
systemctl disable nginx.service

结语:当然Nginx除了反向代理,还有负载均衡等功能,这个就不在本文章范围内了。

都读到这里了,来个 点赞、评论、关注、收藏 吧!

文章作者:IT王小二

首发地址:https://www.itwxe.com/posts/1334c88e/

版权声明:文章内容遵循 署名-非商业性使用-禁止演绎 4.0 国际 进行许可,转载请在文章页面明显位置给出作者与原文链接。

Linux(CentOS7)下Nginx安装的更多相关文章

  1. linux系统下nginx安装目录和nginx.conf配置文件目录

    linux系统下nginx安装目录和nginx.conf配置文件目录 1.查看nginx安装目录 输入命令 # ps  -ef | grep nginx 返回结果包含安装目录 root      26 ...

  2. Linux(CentOS7)下二进制安装MySQL5.7.26

    记录一下自己在 CentOS7 下二进制安装 MySQL5.7.26 的过程,之前使用 Linux(CentOS7)下rpm安装MySQL8.0.16 之后发现 rpm 方式安装不利于维护,也不利于单 ...

  3. Linux(CentOS7)下rpm安装MySQL8.0.16

    记录一下自己在 CentOS7 下 rpm 安装 MySQL8.0.16 的过程. 一.准备工作 1. 下载MySQL所需要的安装包 从 MySQL官网 下载,上传至 CentOS 系统 /usr/l ...

  4. Linux系统下Nginx安装详解

    该随笔为个人原创,后期会根据项目实践实时更新,如若转载,请注明出处,方便大家获得最新博文! 注:安装Nginx需要Linux系统已经安装   openssl-fips-2.0.2.tar.gz zli ...

  5. centos7下nginx安装

    http://www.linuxidc.com/Linux/2016-09/134907.htm 安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Window ...

  6. linux centos7下mysql安装--韩国庆

    首先我先给大家介绍下MariaDB和mysql的区别. 上图,“MySQL之父”的骨灰级程序员Monty,但是mysql被Oracle收购后,Monty又开始去发展另一条数据库的道路,并且以Monty ...

  7. Linux centos7下php安装cphalcon扩展的方法

    说明: 操作系统:CentOS7 php安装目录:/usr/local/php php.ini配置文件路径:/usr/local/php/etc/php.ini 运行环境:LNMP ,PHP7 .安装 ...

  8. Linux(Centos7)下redis5安装、部署、开机自启

    1.什么是redis redis是用C语言开发的一个开源的高性能键值对(key-value)数据库.它通过提供多种键值数据类型来适应不同场景下的存储需求,目前为止redis支持的键值数据类型如下字符串 ...

  9. linux Centos7 下vsftpd 安装与配 FTP

    一.说明 linux 系统下常用的FTP 是vsftp, 即Very Security File Transfer Protocol. 还有一个是proftp(Profession ftp). 我们这 ...

随机推荐

  1. Searching the Web UVA - 1597

      The word "search engine" may not be strange to you. Generally speaking, a search engine ...

  2. DPAPI机制学习

    0x00 前言 ​绝大多数应用程序都有数据加密保护的需求,存储和保护私密信息最安全的方式就是每次需要加密或解密时都从用户那里得到密码,使用后再丢弃.这种方式每次处理信息时都需要用户输入口令,对于绝大多 ...

  3. webpack的构建流程

    一.运行流程 webpack 的运行流程是一个串行的过程,它的工作流程就是将各个插件串联起来 在运行过程中会广播事件,插件只需要监听它所关心的事件,就能加入到这条webpack机制中,去改变webpa ...

  4. poj1182 and 携程预赛2第一题 带权并查集

    题意:       动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A.  现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底 ...

  5. 路由器逆向分析------在QEMU MIPS虚拟机上运行MIPS程序(ssh方式)

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/69652258 在QEMU MIPS虚拟机上运行MIPS程序--SSH方式 有关在u ...

  6. 去除腾讯视频logo水印

    打开F12,然后再console中输入下面代码,即可. document.querySelectorAll(".txp_waterMark_pic").forEach(functi ...

  7. Xshell6连Linux

    一.安装 文件 链接: 提取码:8rmr 二.连Linux 名称填自己喜欢的.续之前,我们保持一样的名字.主机填IP,根据之前Linux填的静态IP去连接. 然后双击,连接 我们用最高权限,填root ...

  8. raft协议

    一.Raft一致性算法 Eureka:Peer To Peer,每个节点的地位都是均等的,每个节点都可以接收写入请求,每个节点接收请求之后,进行请求打包处理,异步化延迟一点时间,将数据同步给 Eure ...

  9. Morgan Stanley Books List:经典金融书籍推荐

    一.经济学 1. 中华帝国的专制制度,佛朗索瓦.魁奈 2. 资本论(共3卷),马恩全集 3. 国家竞争优势,麦克尔.波特 4. Essentials of corporate analysis, by ...

  10. HEVC学习(一) —— HM的使用

    http://blog.csdn.net/hevc_cjl/article/details/8169182 首先自然是先把这个测试模型下载下来,链接地址如下:https://hevc.hhi.frau ...