百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 博客教程 > 正文

Nginx 1.14.2 移植指南(openEuler 20.03 LTS SP1)

connygpt 2024-10-26 09:19 10 浏览

介绍

简要介绍

Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,其特点是占有内存少,并发能力强,支持FastCGI、SSL、Virtual Host、URL Rewrite、gzip等功能,并且支持很多第三方的模块扩展。

开发语言:C

一句话描述:Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器

建议的版本

建议使用版本为“Nginx 1.14.2”。 说明: 本文档适用于Nginx 1.14.2版本,其他版本的Nginx移植步骤也可参考本文档。

环境要求

硬件要求

硬件要求如表1所示。 表1 硬件要求

项目

说明

服务器

TaiShan 200服务器(型号2280)

CPU

鲲鹏920 5250处理器

磁盘分区

对磁盘分区无要求

操作系统要求

操作系统要求如表2所示。 表2 操作系统要求

项目

版本

版本查看命令

openEuler

20.03 LTS SP1

cat /etc/openEuler-release

Kernel

4.19.90

uname -r

配置编译环境

配置Yum源

说明: 如果组网环境处于外网受限情况下,服务器yum命令无法通过外界获取依赖包时,可参考本节内容进行本地源配置。

  • 将操作系统镜像文件openEuler-20.03-LTS-everything-aarch64-dvd.iso文件拷贝到每台服务器的“/root”目录下。
  • 镜像文件挂载。 a. 将“/root”目录下的openEuler操作系统对应iso文件挂载到“/mnt”目录下。 mount /root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt 说明: 该操作单次生效,重启后失效。若需要配置开机启动自动挂载镜像(可选),可参考下面步骤。

1. 打开fstab文件。 vi /etc/fstab

2. 编辑fstab文件,在文件末尾添加如下信息: /root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt iso9660 loop 0 0

3. 保存并退出fstab文件。

  • 添加本地源文件。 a. 进入“/etc/yum.repos.d”目录。 cd /etc/yum.repos.d 说明: 此时,建议将此目录下的*.repo文件移到任意其他备份目录下。 b. 创建local.repo文件。

1. 打开local.repo文件。 vi local.repo

2. 编辑local.repo文件,在local.repo文件中添加如下内容:

[local]
name=local.repo
baseurl=file:///mnt
enabled=1
gpgcheck=0


说明: 其中,baseurl中file路径为镜像挂载路径,与镜像文件挂载中的目录“/mnt” 对应。 3. 保存并退出local.repo文件。 4. 生效本地源。

yum clean all
yum makecache
yum list

安装依赖包

下载并安装依赖包

yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel pcre2-devel perl-devel perl-ExtUtils-Embed openssl openssl-devel

获取源码

本文使用源码编译安装,因此需要获取到Nginx。

  • 下载Nginx源码 cd /homewget https://nginx.org/download/nginx-1.14.2.tar.gz --no-check-certificate

说明: 也可以通过本地浏览器下载源码之后上传到服务器"/home"目录下。 源码地址:https://nginx.org/download/nginx-1.14.2.tar.gz

注意: 若及其需要配置代理才可以访问外网,请参考下面操作配置网络代理。

  • 打开profile文件 vi /etc/profile
  • 添加如下代码后,保存并退出文件。 其中,代理服务用户名、代理服务器密码、代理服务器IP和代理服务端口需要根据当前环境配置
export http_proxy="http://代理服务器名:代理服务器密码@代理服务器IP:代理服务器端口"
export http_proxy=$http_proxy
export no_proxy=127.0.0.1,.huawei.com,localhost,local,.local
  • 使用代理效。 source /etc/profile
  • 查看环境变量中的代理信息。 env
  • 验证代理是否配置成功。 curl www.baidu.com 可以正常解析百度即为配置成功。

编译和安装

  • 解压Nginx安装包。 tar -xvf nginx-1.14.2.tar.gz
  • 进入"nginx-1.14.2"目录。 cd /home/nginx-1.14.2/
  • 配置Nginx。 ./configure --prefix=/usr/local/nginx --with-http_ssl_module 说明:
  • --prefix=PATH:用来制定Nginx的安装目录,默认安装目录为"/usr/local/nginx"。
  • 不需要配置with-http_stub_status_module模块,该统计模块会影响Nginx性能。
  • 编译并安装Nginx make -j96 && make -j96 install 说明: -j96: 充分利用CPU多核优势,加快编译安装速度。 CPU 的核数可以通过lscpu查看。 5.查看安装目录。 ls /usr/local/nginx

运行和验证

生成证书

  • 进入"/usr/local/nginx"目录,在该目录下生成密钥key。 cd /usr/local/nginxopenssl genrsa -des3 -out server_2048.key 2048 会有两次要求输入密码,输入同一个即可,此时会生成server_2048.key文件。
[root@localhost nginx]# openssl genrsa -des3 -out server_2048.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
..................................................................................+++++
................+++++
e is 65537 (0x010001)
Enter pass phrase for server_2048.key:
Verifying - Enter pass phrase for server_2048.key:

说明: 可通过如下命令实现免密码使用此文件: openssl rsa -in server_2048.key -out -server_2048.key

[root@localhost nginx]# openssl rsa -in server_2048.key -out -server_2048.key
Enter pass phrase for server_2048.key
writing RSA key
  • 创建服务器证书的申请文件。
openssl req -new -key server_2048.key -out server_2048.csr
[root@localhost nginx]# openssl req -new -key server_2048.key -out server_2048.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

输入1中设置的密码,其中Country Name 选项输入CN,其他选项可以不填。 3. 重写密钥key。 openssl rsa -in server_2048.key -out server_2048.key

[root@localhost nginx]# openssl rsa -in server_2048.key -out server_2048.key
writing RSA key
  • 生成证书。 openssl x509 -req -days 365 -in server_2048.csr -signkey server_2048.key -out server_2048.crt
[root@localhost nginx]# openssl x509 -req -days 365 -in server_2048.csr -signkey server_2048.key -out server_2048.crt
Signature ok
subject=C = CN, ST = Some-State, O = Internet Widgits Pty Ltd
Getting Private key

输入1中设置的密码。若已经设置免密码使用该文件,则无需输入密码。

配置功能

配置Nginx的HTTPS功能

  • 打开nginx.conf配置文件。 vi /usr/local/nginx/conf/nginx.conf
  • 修改nginx.conf配置文件以下三处配置后,保存并退出(Esc+ :wq)。
  • 定义Nginx运行的用户权限user为root。
  • 修改listen监测端口,可以使用默认端口,本文修改为20000。
  • 指定ssl_certificate和ssl_certificate_key文件。

原文默认内容:

#user  nobody;
...
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

修改后内容:

user  root;
 ...
     HTTPS server
    
    server {
        listen       20000 ssl;
        server_name  localhost;

        ssl_certificate      /usr/local/nginx/server_2048.crt;
        ssl_certificate_key  /usr/local/nginx/server_2048.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

配置Nginx的HTTP功能

  • 打开nginx.conf配置文件。 vi /usr/local/nginx/conf/nginx.conf
  • 修改nginx.conf配置文件以下三处配置后,保存并退出(Esc+ :wq)。定义Nginx运行的用户权限user为root。修改listen监测端口,可以使用默认端口,本文修改为10000。

原文件默认内容:

user  root;
...
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
   }
}

修改后内容:

user  root;
...
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on

    server {
        listen       10000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
   }
}

运行Nginx

  • 启动Nginx(两种方式)。
  • 通过Service服务启动(使用该方法需要先将Nginx加入Service服务再执行启动命令)。修改“/etc/init.d/nginx”文件。 a. 删除原文件nginx。 rm -rf /etc/init.d/nginx b. 新建nginx文件。 vi /etc/init.d/nginx c. 添加如下内容后,保存并退出
	   #!/bin/bash
	   # chkconfig: 2345 10 90
	   # description: nginx
	   case "$1" in
	     'start')
	       /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
	       echo "$0_start";
	      ;;
	    'stop')
	     /usr/local/nginx/sbin/nginx -s quit
	     echo "$0_stop";
	     ;;
	   esac
 2. 修改“/etc/init.d/nginx”文件权限。

chmod 777 /etc/init.d/nginx 3. 将Nginx加入chkconfig管理列表。 chkconfig --add /etc/init.d/nginx 4. 设置Nginx开机自动启动。 chkconfig nginx on 5. 启动Nginx。 service nginx start - 通过脚本命令启动。 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 2. 查看Nginx的进程。 ps -ef | grep nginx

[root@localhost nginx]# ps -ef | grep nginx
root        9463       1  0 18:22 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
root        9464    9463  0 18:22 ?        00:00:00 nginx: worker process
root        9466    1352  0 18:23 ttyAMA0  00:00:00 grep --color=auto nginx

说明: 关闭Nginx命令如下(3种方式,可选)。业务运行中不要执行该命令。

  • 通过Service服务关闭。 service nginx stop
  • 通过脚本命令关闭。 /usr/local/nginx/sbin/nginx -s quit
  • 使用结束进程命令。
```pkill nginx```
[root@localhost nginx]# pkill nginx
[root@localhost nginx]# ps -ef | grep nginx
root        9469    1352  0 18:27 ttyAMA0  00:00:00 grep --color=auto nginx

验证Nginx

  • 查看Nginx的监测端口(10000是HTTP监测端口,20000是HTTPS监测端口)。 netstat -anp | grep 10000netstat -anp | grep 20000netstat -anpt
[root@localhost nginx]# netstat -anp | grep 10000
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      9535/nginx: master  
[root@localhost nginx]# netstat -anp | grep 20000
tcp        0      0 0.0.0.0:20000           0.0.0.0:*               LISTEN      9535/nginx: master  
[root@localhost nginx]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      9535/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      775/sshd: /usr/sbin 
  • 查看Nginx的HTML文件所在目录。 ll -h /usr/local/nginx/html/
[root@localhost nginx]# ll -h /usr/local/nginx/html/
total 8.0K
-rw-r--r--. 1 root root 537 Mar 20 16:46 50x.html
-rw-r--r--. 1 root root 612 Mar 20 16:46 index.html
  • 验证HTTPS功能。 通过curl本地访问Nginx的HTML页面。 curl -k https://127.0.0.1:20000/index.html
[root@localhost nginx]# curl -k  https://127.0.0.1:20000/index.html



Welcome to nginx!

    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }



<h1>Welcome to nginx!</h1>
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

For online ation and support please refer to
<a href="#" class="white">nginx.org</a>.

Commercial support is available at
<a href="#" class="white">nginx.com</a>.

<em>Thank you for using nginx.</em>


  1. 验证HTTP功能。 通过curl本地访问Nginx的HTML页面。 curl http://127.0.0.1:10000/index.html
[root@localhost nginx]# curl http://127.0.0.1:10000/index.html



Welcome to nginx!

    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }



<h1>Welcome to nginx!</h1>
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

For online ation and support please refer to
<a href="#" class="white">nginx.org</a>.

Commercial support is available at
<a href="#" class="white">nginx.com</a>.

<em>Thank you for using nginx.</em>


卸载Nginx

编译安装只是生成对应的文件,不涉及卸载,直接删除对应的安装目录即可。 rm -rf /usr/local/nginx

相关链接:

1. openEuler官网:www.openeuler.org/

2. OS迁移专区: https://www.openeuler.org/zh/migration/download/

3. openEuler兼容性列表:https://www.openeuler.org/zh/compatibility/

4. openEuler迁移指南:https://www.openeuler.org/zh/blog/2022-08-29/migration.html

相关推荐

3分钟让你的项目支持AI问答模块,完全开源!

hello,大家好,我是徐小夕。之前和大家分享了很多可视化,零代码和前端工程化的最佳实践,今天继续分享一下最近开源的Next-Admin的最新更新。最近对这个项目做了一些优化,并集成了大家比较关注...

干货|程序员的副业挂,12个平台分享

1、D2adminD2Admin是一个完全开源免费的企业中后台产品前端集成方案,使用最新的前端技术栈,小于60kb的本地首屏js加载,已经做好大部分项目前期准备工作,并且带有大量示例代码,助...

Github标星超200K,这10个可视化面板你知道几个

在Github上有很多开源免费的后台控制面板可以选择,但是哪些才是最好、最受欢迎的可视化控制面板呢?今天就和大家推荐Github上10个好看又流行的可视化面板:1.AdminLTEAdminLTE是...

开箱即用的炫酷中后台前端开源框架第二篇

#头条创作挑战赛#1、SoybeanAdmin(1)介绍:SoybeanAdmin是一个基于Vue3、Vite3、TypeScript、NaiveUI、Pinia和UnoCSS的清新优...

搭建React+AntDeign的开发环境和框架

搭建React+AntDeign的开发环境和框架随着前端技术的不断发展,React和AntDesign已经成为越来越多Web应用程序的首选开发框架。React是一个用于构建用户界面的JavaScrip...

基于.NET 5实现的开源通用权限管理平台

??大家好,我是为广大程序员兄弟操碎了心的小编,每天推荐一个小工具/源码,装满你的收藏夹,每天分享一个小技巧,让你轻松节省开发效率,实现不加班不熬夜不掉头发,是我的目标!??今天小编推荐一款基于.NE...

StreamPark - 大数据流计算引擎

使用Docker完成StreamPark的部署??1.基于h2和docker-compose进行StreamPark部署wgethttps://raw.githubusercontent.com/a...

教你使用UmiJS框架开发React

1、什么是Umi.js?umi,中文可发音为乌米,是一个可插拔的企业级react应用框架。你可以将它简单地理解为一个专注性能的类next.js前端框架,并通过约定、自动生成和解析代码等方式来辅助...

简单在线流程图工具在用例设计中的运用

敏捷模式下,测试团队的用例逐渐简化以适应快速的发版节奏,大家很早就开始运用思维导图工具比如xmind来编写测试方法、测试点。如今不少已经不少利用开源的思维导图组件(如百度脑图...)来构建测试测试...

【开源分享】神奇的大数据实时平台框架,让Flink&amp;Spark开发更简单

这是一个神奇的框架,让Flink|Spark开发更简单,一站式大数据实时平台!他就是StreamX!什么是StreamX大数据技术如今发展的如火如荼,已经呈现百花齐放欣欣向荣的景象,实时处理流域...

聊聊规则引擎的调研及实现全过程

摘要本期主要以规则引擎业务实现为例,陈述在陌生业务前如何进行业务深入、调研、技术选型、设计及实现全过程分析,如果你对规则引擎不感冒、也可以从中了解一些抽象实现过程。诉求从硬件采集到的数据提供的形式多种...

【开源推荐】Diboot 2.0.5 发布,自动化开发助理

一、前言Diboot2.0.5版本已于近日发布,在此次发布中,我们新增了file-starter组件,完善了iam-starter组件,对core核心进行了相关优化,让devtools也支持对IAM...

微软推出Copilot Actions,使用人工智能自动执行重复性任务

IT之家11月19日消息,微软在今天举办的Ignite大会上宣布了一系列新功能,旨在进一步提升Microsoft365Copilot的智能化水平。其中最引人注目的是Copilot...

Electron 使用Selenium和WebDriver

本节我们来学习如何在Electron下使用Selenium和WebDriver。SeleniumSelenium是ThoughtWorks提供的一个强大的基于浏览器的开源自动化测试工具...

Quick &#39;n Easy Web Builder 11.1.0设计和构建功能齐全的网页的工具

一个实用而有效的应用程序,能够让您轻松构建、创建和设计个人的HTML网站。Quick'nEasyWebBuilder是一款全面且轻巧的软件,为用户提供了一种简单的方式来创建、编辑...