Py学习  »  NGINX

《阿里云服务器搭建》------ 安装nginx

tomatocc • 4 年前 • 242 次点击  

本系列教程的搭建环境为阿里云服务器,其他服务器可作为参考。

本文主要讲述在服务器中搭建nginx服务器

1. 首先到 nginx官网 下载 nginx-x.x.x.tar.gz 的压缩包。

在这里插入图片描述

1.下载完之后,将tar包通过sftp放到阿里云服务器上。
2.然后通过 tar -zxvf nginx-1.17.7.tar.gz 命令将tar包解压

在这里插入图片描述
在这里插入图片描述

2.准备对ngnix进行编译
  1. 安装编译依赖gcc环境
    [root@tomatocc app]# yum install gcc-c++
    在这里插入图片描述
  2. 安装PCRE
    PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
    #注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
    [root@tomatocc app]# yum install -y pcre pcre-devel
    在这里插入图片描述
  3. 安装zlib
    zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
    [root@tomatocc app]# yum install -y zlib zlib-devel
    在这里插入图片描述
  4. 安装openssl
    OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
    nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
    [root@tomatocc app]# yum install -y openssl openssl-devel
    在这里插入图片描述
3.编译安装nginx

1.cd 到nginx的目录下面

[root@tomatocc app]# cd nginx-1.17.7
[root@tomatocc nginx-1.17.7]# ll
total 792
drwxr-xr-x 6 1001 1001   4096 Dec 29 20:22 auto
-rw-r--r-- 1 1001 1001 301572 Dec 24 23:00 CHANGES
-rw-r--r-- 1 1001 1001 460207 Dec 24 23:00 CHANGES.ru
drwxr-xr-x 2 1001 1001   4096 Dec 29 20:22 conf
-rwxr-xr-x 1 1001 1001   2502 Dec 24 23:00 configure
drwxr-xr-x 4 1001 1001   4096 Dec 29 20:22 contrib
drwxr-xr-x 2 1001 1001   4096 Dec 29 20:22 html
-rw-r--r-- 1 1001 1001   1397 Dec 24 23:00 LICENSE
-rw-r--r-- 1 root root    355 Dec 29 20:34 Makefile
drwxr-xr-x 2 1001 1001   4096 Dec 29 20:22 man
drwxr-xr-x 3 root root   4096 Dec 29 20:35 objs
-rw-r--r-- 1 1001 1001     49 Dec 24 23:00 README
drwxr-xr-x 9 1001 1001   4096 Dec 29 20:22 src
[root@tomatocc nginx-1.17.7]# 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

2.对该目录的资源进行编译,命令如下(可以直接复制执行即可)

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  1. 执行下面命令
[root@tomatocc nginx-1.17.7]# make
  • 1
  1. 执行下面命令
[root@tomatocc nginx-1.17.7]# make install
  • 1
  1. 启动nginx

切换到安装位置,也就是之前配置configure的cd /usr/local/nginx
注:nginx.conf 是 nginx 的默认配置文件。也可以使用 nginx -c 指定配置文件启动sbin/nginx#启动失败按照提示创建对应client目录#启动成功查看nginx进程(master进程和worker进程)

在这里插入图片描述

在这里插入图片描述
备:可以关注另一篇博文,关于nginx详细配置
《WEB服务器——Nginx》Nginx配置详解

【阿里云服务器搭建】系列教程

《阿里云服务器搭建》------ 安装jdk
《阿里云服务器搭建》------ 安装Tomcat
《阿里云服务器搭建》------ 安装MySql
《阿里云服务器搭建》------ 安装Jenkins
《阿里云服务器搭建》------ 安装Git
《阿里云服务器搭建》------ 安装Maven
《阿里云服务器搭建》------ 实现Linux和Jenkins的链接
《阿里云服务器搭建》------ 实现Jenkins和github之间自动化部署项目
《阿里云服务器搭建》------ 实现Github和本地仓库链接
《阿里云服务器搭建》------ 实现Jenkins和github之间自动化部署Maven web项目
《阿里云服务器搭建》------ 部署多个tomcat,防止jenkins与项目共用一个端口

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52157
 
242 次点击