鲲鹏 ARM 架构 麒麟 Lylin v10 安装 Nginx (离线)

最近做一个银行的项目,银行的服务器是鲲鹏ARM架构的服务器,并且是麒麟v10的系统,这里记录一下在无法访问外网安装 Nginx 的方法。

其他文章:

鲲鹏 ARM 架构 麒麟 Lylin v10 安装 Mysql8.3 (离线)-CSDN博客

鲲鹏 ARM 架构 麒麟 Lylin v10 安装 Node 和 NVM (离线)-CSDN博客

鲲鹏 ARM 架构 麒麟 Lylin v10 安装 Pm2 (离线)-CSDN博客

鲲鹏 ARM 架构 麒麟 Lylin v10 安装 PHP 和 adminer (离线)-CSDN博客

下载nginx和关联的库

下载 nginx nginx-1.24.0.tar.gz https://nginx.org/en/download.html

选择 Stable version 的 nginx-1.24.0,这个是稳定版本,不会有太多的 bug

下载 pcre pcre2-10.43.tar.gz

官方:https://www.pcre.org/

github:https://github.com/PCRE2Project/pcre2/releases

选择 Latest release 的 pcre2-10.43

下载 zlib zlib-1.3.1.tar.gz

官方:https://zlib.net/

github:https://github.com/madler/zlib/releases

选择 Latest release 的 zlib-1.3.1.tar.gz

下载 OpenSSL openssl-3.2.1.tar.gz

官方:https://www.openssl.org/

github:https://github.com/openssl/openssl/releases

选择 Latest release 的 openssl-3.2.1.tar.gz

把下载的压缩包都上传到服务器root目录下

安装nginx和相关库

安装 PCRE 库,用于支持 Nginx 的 Rewrite 模块,因为 Nginx 使用 PCRE 来解析正则表达式

tar -zxvf pcre2-10.43.tar.gz

cd pcre2-10.43

./configure

make

make install

安装 zlib 库,用于支持 Nginx 的 Gzip 模块,因为 Nginx 使用 zlib 来压缩和解压缩数据

tar -zxvf zlib-1.3.1.tar.gz

cd zlib-1.3.1

./configure

make

make install

安装 OpenSSL 库,用于支持 Nginx 的 SSL 模块,因为 Nginx 使用 OpenSSL 来加密和解密数据

这个make时间会比较长,耐心等待

tar -zxvf openssl-3.2.1.tar.gz

cd openssl-3.2.1

./config

make

make install

安装 Nginx 并指定安装路径,确保替换 nginx-version, pcre-version, zlib-version, 和 openssl-version 为实际的版本号

这个make时间会比较长,耐心等待

tar -zxvf nginx-1.24.0.tar.gz

cd nginx-1.24.0

./configure --sbin-path=/usr/local/nginx/sbin/nginx \

  --conf-path=/usr/local/nginx/conf/nginx.conf \

  --error-log-path=/usr/local/nginx/logs/error.log \

  --http-log-path=/usr/local/nginx/logs/access.log \

  --with-pcre=../pcre2-10.43 \

  --with-zlib=../zlib-1.3.1 \

  --with-openssl=../openssl-3.2.1 \

  --with-http_ssl_module

make

make install

配置Nginx服务

配置 PATH 环境变量

echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> ~/.bashrc

source ~/.bashrc

创建网站根目录

mkdir -p /home/www/wwwroot/baswei

创建测试页面

vi /home/www/wwwroot/baswei/index.html

写入以下内容

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>测试页面</title>

</head>

<body>

<h1>欢迎来到鲲鹏服务器上的 Nginx 测试页面!</h1>

<p>这是一个简单的测试页面,用于验证 Nginx 是否正确配置。</p>

</body>

</html>

启动 Nginx

nginx

验证 Nginx 是否启动成功

ps -ef | grep nginx

确认nginx是以哪个用户运行的,一般主进程是以root用户启动的,工作进程是以nobody用户启动的

ps -eo user,group,comm | grep nginx

设置网站根目录权限,确保工作进程用户(nobody)可以读取和执行

将网站根目录及其子目录和文件的所有权更改为 nobody 用户和组。

sudo chown -R nobody:nobody /home/

对所有目录设置权限为 755(即目录所有者和组可以读取、写入和执行,其他用户可以读取和执行)。

sudo find /home/ -type d -exec chmod 755 {} \;

对所有文件设置权限为 644(即文件所有者可以读取和写入,文件所有组可以读取,其他用户可以读取)。

sudo find /home/www/wwwroot/baswei -type f -exec chmod 644 {} \;

验证权限设置是否成功

ls -ld /home /home/www /home/www/wwwroot /home/www/wwwroot/baswei/ /home/www/wwwroot/baswei/index.html

# 如果输出结果如下,则表示权限设置成功

# drwxr-xr-x 3 nobody nobody 4096 4月  15 16:00 /home

# drwxr-xr-x 3 nobody nobody 4096 4月  15 16:00 /home/www

# drwxr-xr-x 3 nobody nobody 4096 4月  15 16:00 /home/www/wwwroot

# drwxr-xr-x 2 nobody nobody 4096 4月  15 16:00 /home/www/wwwroot/baswei/

# -rw-r--r-- 1 nobody nobody  228 4月  15 16:00 /home/www/wwwroot/baswei/index.html

设置网站目录权限,允许其他用户访问 (可选,不是安全的)

chmod o+x /home /home/www /home/www/wwwroot /home/www/wwwroot/baswei/ /home/www/wwwroot/baswei/index.html

备份 Nginx 配置文件

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

# 编辑 Nginx 配置文件

vi /usr/local/nginx/conf/nginx.conf

# 添加以下内容

server {

listen       80;

# server_name 替换为自己的域名或 IP 地址

server_name  123.60.220.94;

location / {

root   /home/www/wwwroot/baswei;

index  index.html index.htm;

}

}

验证 Nginx 配置是否正确

nginx -t

重启 Nginx

nginx -s reload

清空 Nginx 的错误日志

echo "" > /usr/local/nginx/logs/error.log

查看 Nginx 的错误日志

more  /usr/local/nginx/logs/error.log

设置 Nginx 开机自启

创建 Nginx 的 systemd 服务文件

vi /etc/systemd/system/nginx.service

添加以下内容

[Unit]

Description=The NGINX HTTP and reverse proxy server

After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

[Install]

WantedBy=multi-user.target

重新加载 systemd 配置

systemctl daemon-reload

启动 Nginx 服务

systemctl start nginx

验证 Nginx 服务是否启动成功

systemctl status nginx

设置 Nginx 服务开机自启

systemctl enable nginx

  • 18
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值