Linux下nginx的yum安装、源码安装、OpenResty的源码安装

Stella981
• 阅读 637

Linux下nginx的安装

安装环境:

# cat /proc/version
Linux version 3.10.0-123.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Mon Jun 30 12:09:22 UTC 2014

# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 

yum安装

  1. 设置yum仓库地址vi /etc/yum.repos.d/nginx.repo

    [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true

  2. 使用yum安装:

    yum install -y nginx

安装完成后配置文件所在目录为/etc/nginx

  1. nginx的启动与停止:
  • 启动nginx:nginxsystemctl start nginx
  • 停止nginx:nginx -s stopsystemctl stop nginx
  1. 查看nginx是否启动成功。

    ps -ef|grep nginx

    root 1830 1 0 22:45 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 1831 1830 0 22:45 ? 00:00:00 nginx: worker process root 1835 1638 0 22:45 pts/0 00:00:00 grep --color=auto nginx

    systemctl status nginx

    ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2020-10-07 22:45:12 EDT; 22s ago Docs: http://nginx.org/en/docs/ Process: 1817 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=1/FAILURE) Process: 1829 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) CGroup: /system.slice/nginx.service ├─1830 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─1831 nginx: worker process Oct 07 22:45:12 localhost.localdomain systemd[1]: Starting nginx - high performance web server... Oct 07 22:45:12 localhost.localdomain systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory Oct 07 22:45:12 localhost.localdomain systemd[1]: Started nginx - high performance web server.

  2. 访问网站http://localhost/

  3. 卸载nginx。

    yum list nginx

    Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile

    • base: mirrors.ustc.edu.cn
    • centos-sclo-rh: mirrors.163.com
    • centos-sclo-sclo: mirrors.ustc.edu.cn
    • extras: mirrors.ustc.edu.cn
    • updates: mirrors.ustc.edu.cn Installed Packages nginx.x86_64 1:1.18.0-1.el7.ngx @nginx-stable

    yum remove nginx.x86_64

    Loaded plugins: fastestmirror ... ...

源码安装

源码安装的方式方便对nginx进行自定义的配置以及安装插件。

  1. 下载源码,下载地址:http://nginx.org/en/download.html,这里使用的版本为`nginx-1.18.0.tar.gz`。

  2. 解压nginx-1.18.0.tar.gz

    tar xf nginx-1.18.0.tar.gz

  3. 安装可能需要的依赖:

    yum -y install autoconf automake make

    yum -y install gcc gcc-c++

    yum -y install pcre pcre-devel

    yum -y install zlib zlib-devel

    yum install -y openssl openssl-devel

  4. 配置:

    cd nginx-1.18.0

    ./configure

  5. 安装:

    make && make install

安装完成后的二进制文件和配置文件在/usr/local/nginx目录下。

  1. 配置环境变量:

    vi /etc/profile

    最后增加 export PATH=$PATH:/usr/local/nginx/sbin

    source /etc/profile

  2. 安装成为服务:

    vi nginx.service

    [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target

    [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/nginx/sbin/nginx -s stop

    [Install] WantedBy=multi-user.target

    systemctl daemon-reload

OpenResty的安装

OpenResty是一个基于Nginx与Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项。

  1. 下载OpenResty,下载地址:https://openresty.org/download/openresty-1.17.8.2.tar.gz

  2. 安装:

    tar xf openresty-1.17.8.2.tar.gz

    cd openresty-1.17.8.2

    ./configure

    make && make install

  3. 配置环境变量:

    vi /etc/profile

    最后追加 export PATH=$PATH:/usr/local/openresty/bin

    cd /usr/local/openresty/bin

    ll | grep openresty

    lrwxrwxrwx. 1 root root 37 Oct 9 14:09 openresty -> /usr/local/openresty/nginx/sbin/nginx

openresty是一个指向/usr/local/openresty/nginx/sbin/nginx的软链接,其实openresty内置了一个nginx,使用方法与nginx一样。

# openresty -V
nginx version: openresty/1.17.8.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.17 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.8 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
2年前
Java获得今日零时零分零秒的时间(Date型)
publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS
Stella981 Stella981
2年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Easter79 Easter79
2年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这