【Linux-ARM】安装Nginx

环境

Linux ARM 64位

安装

1. 下载

> https://github.com/nginx/nginx/tags
> 选择 1.22.0版本源码

2. 将文件拷贝到服务器中

mkdir /opt/nginx
> /opt/nginx

3. 解压

cd /opt/nginx
# 将 nginx-release-1.22.0.tar.gz 拷贝进去 
tar -zxvf nginx-release-1.22.0.tar.gz

4. 编译前准备

# 更新
yum -y update
# 需要使用https执行指令
# /opt/nginx/nginx/configure --with-http_ssl_module
# 不需要使用https执行
# /opt/nginx/nginx/configure
# 编译如果提示./configure: error: the HTTP rewrite module requires the PCRE library.,则执行yum -y install pcre-devel后重新编译
# 提示./configure: error: the HTTP gzip module requires the zlib library.,则执行yum install -y zlib-devel后重新编译
yum -y install pcre-devel
yum install -y zlib-devel
# error: SSL modules require the OpenSSL library
yum -y install openssl
yum -y install openssl-devel

5. 编译

cd /opt/nginx/nginx-release-1.22.0

./auto/configure
    --prefix=/usr/local/nginx # 定义将保存服务器文件的目录
    --sbin-path=/usr/local/nginx/nginx # 设置 nginx 可执行文件的名称
    --conf-path=/usr/local/nginx/nginx.conf # 设置nginx.conf配置文件的名称
    #--error-log-path=/usr/local/nginx/logs/error.log # 设置主要错误、警告和诊断文件的名称
    --pid-path=/usr/local/nginx/nginx.pid # 设置nginx.pid将存储主进程的进程 ID 的文件的名称
    --with-http_ssl_module # 允许构建一个将 HTTPS 协议支持添加 到 HTTP 服务器的模块

cd /opt/nginx/nginx-release-1.22.0
make && make install

6. 启动

# 启动
cd /usr/local/nginx
# 启动
./nginx

7. 停止服务

cd /usr/local/nginx/
# 关闭
./nginx -s quit

8. 开启防火墙端口

firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --reload

9. 测试

curl http://127.0.0.1:3000

10. 设置开机启动

  • 进入目录 cd /usr/lib/systemd/system
  • nginx.service拷贝到对应的服务器上
  • 重新加载服务 systemctl daemon-reload
  • 设置为开机启动 systemctl enable nginx.service
  • 查看是否已开机启动 systemctl is-enabled nginx.service
  • 查看服务状态 systemctl status nginx.service
  • 启用服务 systemctl enable nginx.service
  • 启动服务 systemctl start nginx.service
  • 停止服务 systemctl stop nginx.service

11. 部署

  • 前端编译完成
  • 将编译后的产物,放到/usr/local/nginx/html/
  • 配置nginx代理 /usr/local/nginx/nginx.config
    • 添加配置 http.server.location /test { proxy_pass http://IP:8881/test; }
  • 重新加载 /usr/local/nginx/nginx -s reload

附录

nginx.service

#
# /usr/lib/systemd/system
# systemd service file for Nginx Server forking server
#
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
User=root
Type=forking
PIDFile=/usr/local/nginx/nginx.pid
#Environment="JAVA_HOME=/opt/openjdk/jdk1.8.0_311" #改成自己的jdk路径,因为服务脚本的环境和系统环境变量不能共享,所以还得设置才能生效。
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /usr/local/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /usr/local/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

或者

#
# /usr/lib/systemd/system
# systemd service file for Nginx Server forking server
#
[Unit]
Description=Nginx Server
Documentation=Nginx 1.22.0
Documentation=https://rocketmq.apache.org/
Documentation=https://github.com/nginx/nginx
Documentation=https://nginx.org/en/docs/beginners_guide.html

After=network.target

[Service]
User=root
Type=forking
Environment="JAVA_HOME=/opt/openjdk/jdk1.8.0_311" #改成自己的jdk路径,因为服务脚本的环境和系统环境变量不能共享,所以还得设置才能生效。
ExecStart=/usr/local/nginx/nginx
ExecReload=/usr/local/nginx/nginx -s reload
ExecStop=/usr/local/nginx/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琴 韵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值