五、nginx的安装部署

摘要:
g'-i/etc/yum.repos.d/epel.repo/etc/yum.repos.d/epel-testing.repo或者直接使用清华源的epel[epel]name=ExtraPackagesforEnterpriseLinux7-$basearchbaseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearchfailovermethod=priorityenabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-73、更新yum源yummakecachefast4、yum安装nginxyuminstall-ynginx5、启动nginxsystemctlstartnginx.servicesystemctlenablednginx.service6、测试nginx查看nginx是否安装成功[root@inode1~]#rpm-qanginxnginx-1.16.1-1.el7.x86_64查看nginx进程[root@inode1~]#ps-ef|grepnginxroot1212431005:28?
nginx的安装部署及升级

nginx的官网:http://nginx.org

先来看下nginx最新的版本信息

五、nginx的安装部署第1张

nginx最新的主流版本(mainline version):1.19.2

nginx稳定版本(stable version):1.18.0

其它稳定版本(legacy versions)

一、实验环境

[root@inode1 ~]# uname -r
3.10.0-862.el7.x86_64
[root@inode1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804(Core) 
​
ip地址:192.168.32.101

二、yum安装

1、安装epel源

yum install -y epel-release

2、把epel源的地址替换为清华开源镜像站的地址

sed -e 's!^metalink=!#metalink=!g'-e 's!^#baseurl=!baseurl=!g'-e 's!//download.fedoraproject.org/pub!//mirrors.tuna.tsinghua.edu.cn!g'-e 's!http://mirrors.tuna!https://mirrors.tuna!g'-i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo

或者直接使用清华源的epel

[epel]
name=Extra Packages for Enterprise Linux 7 -$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

3、更新yum源

yum makecache fast

4、yum安装nginx

yum install -y nginx

5、启动nginx

systemctl start nginx.service
systemctl enabled nginx.service

6、测试nginx

查看nginx是否安装成功

[root@inode1 ~]# rpm -qa nginx
nginx-1.16.1-1.el7.x86_64

查看nginx进程

[root@inode1 ~]# ps -ef |grepnginx
root     121243      1  0 05:28 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx    121244 121243  0 05:28 ?        00:00:00nginx: worker process
root     121275 120117  0 05:28 pts/0    00:00:00 grep --color=auto nginx

查看nginx的80端口

[root@inode1 ~]# netstat -antlp|grep 80tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      121243/nginx: maste 
tcp6       0      0 :::80                   :::*                    LISTEN      121243/nginx: maste 

访问nginx

五、nginx的安装部署第2张

三、nginx的源码安装

以nginx-1.16.0为例:

1、安装nginx的依赖软件包

yum install -y gcc gcc-c++ make pcre pcre-devel openssl openssl-devel zlib zlib-devel

2、创建nginx进程运行的用户www

useradd -s /sbin/nologin -M www

3、nginx官方网站下载nginx-1.16.0的源码包

mkdir -p /server/tools
cd /server/tools
wget -c http://nginx.org/download/nginx-1.16.0.tar.gz

4、解压nginx

tar -xf nginx-1.16.0.tar.gz

5、编译安装nginxcd nginx-1.16.0

./configure --prefix=/usr/local/nginx 
--user=www
--group=www
--with-http_ssl_module
--with-http_stub_status_module make && make install
#./configure 预编译命令,后面跟编译参数可以使用./configure --help (-h)查看参数信息
#--with-xxx_module 预编译启动的模块
#--without-xxx_module b预编译不启动的模块
#--add-module=PATH 添加第三方模块
#--error-log-path=/var/log/nginx/error.log 设置配置文件的路径
#make 编译
#make install 编译安装

马哥推荐

useradd -r -s /sbin/nologin www
./configure --prefix=/usr/local/nginx
--user=www
--group=www
--with-http_ssl_module
--with-http_v2_module
--with-http_realip_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-pcre
--with-stream
--with-stream_ssl_module
--with-stream_realip_module
make && make install

6、创建nginx命令的软连接

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx

7、启动nginx,并查看nginx进程和端口号

nginx
​
[root@inode1 nginx-1.16.0]# ps -ef |grepnginx
root     125148      1  0 05:51 ?        00:00:00nginx: master process nginx
www      125149 125148  0 05:51 ?        00:00:00nginx: worker process
​
[root@inode1 nginx-1.16.0]# netstat -antlp|grep 80tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      125148/nginx: maste 

8、访问nginx

五、nginx的安装部署第3张

四、nginx的命令说明

-V --- 查看nginx软件编译配置参数

[root@inode1 nginx-1.16.0]# nginx -V
nginx version: nginx/1.16.0built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module

-v --- 查看nginx软件版本

[root@inode1 nginx-1.16.0]# nginx -v
nginx version: nginx/1.16.0

-t --- 检查nginx配置文件语法格式是否正确

[root@inode1 nginx-1.16.0]# nginx -t
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

-s --- 用于管理nginx服务运行状态

stop     停止nginx服务
nginx -s stop 
​
reload   平滑重启nginx服务器(修改配置文件后,重启加载新的配置文件)
nginx -s reload 

重启nginx服务

nginx -s stop 先停止
nginx 再启动

免责声明:文章转载自《五、nginx的安装部署》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇优雅的命名java常见3种文件上传速度对比和文件上传方法详细代码下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

helm install

reference 前提:已安装k8s:v1.10.4 helm install on master(无需下载官方tar包) 链接:https://pan.baidu.com/s/1Ji3Ru1pTQybq_gAiuE9DrQ 密码:0q3t 步骤:将helm.tar 解压移动到/usr/local/bin/helm下 helm init helm in...

前端访问服务器

本地部署前端访问服务器    PS:本系列内容进度节奏会放的很慢,每次知识点都尽量少一点,这样大家接触的知识点少了,会更容易理解,因为少即是多。另外,对于后面代码部分,虽然尽量不用那些复杂的封装和类,但它并不表示看了就能全部记住,并懂得每个函数的用法,在什么时候去调用,清楚它输入的参数类型、能处理的参数类型和输出的结果是什么。它需要动手去调用,去大量的...

Nginx 笔记与总结(13)Nginx 的 gzip 压缩

使用 FireFox(40.0)访问博客园(http://www.cnblogs.com/),观察 http 头信息 请求头信息: Accept-Encoding gzip, deflate 表示浏览器接受的压缩方式有 gzip 和 deflate 响应头信息: Content-Encoding gzip 表示服务器返回内容的压缩方式是 gzip 注意...

nginx配置跨域(CORS)、防盗链(valid_referers)、缓存(expires)、压缩(gzip)

环境: centos6/7,nginx-1.9.15. 摘要说明: 上一篇主要讲述nginx下的常用内置变量及if语句; 本章节主要讲述nginx的如何配置跨域、缓存、压缩; 步骤: 1.跨域 场景:首先我们举例看看什么叫做跨域: 当我们加载static.xxxx.com的页面之后,在js中调用www.xxxx.com接口,这个时候就叫做跨域;因为请求的...

nginx gzip压缩配置

gzip(GNU-ZIP)是一种压缩技术。经过gzip压缩后页面大小可以变为原来的30%甚至更小,这样,用户浏览页面的时候速度会块得多。gzip 的压缩页面需要浏览器和服务器双方都支持,实际上就是服务器端压缩,传到浏览器后浏览器解压并解析。浏览器那里不需要我们担心,因为目前的巨大多数浏览器 都支持解析gzip过的页面。Nginx的压缩输出有一组gzip压缩...

Nginx的启动、停止与重启

启动启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 停止nginx的停止有三种方式: 从容停止   1、查看进程号 [root@LinuxServe...