【无标题】

该文档提供了一步一步的指导,包括在Linux上安装Nginx1.24.0所需的前提条件,如GCC、PCRE、Zlib和OpenSSL的安装,以及防火墙设置,创建用户,设置权限,编译和安装Nginx,修改配置文件,实现开机自启服务的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx linux部署手册

文档文件 链接地址密码:h3qk

一. 安装前提

描述:

描述名称备注
Nginx 版本nginx-1.24.0 稳定版
安装前提依赖gccyum -y install gcc-c++
安装前提依赖pcre pcre-develyum install -y pcre pcre-devel
安装前提依赖zlib zlib-develyum install -y zlib zlib-devel
安装前提依赖openssl openssl-develyum install -y openssl openssl-devel

防火墙设置

root 用户执行

# 开启8080端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@localhost ~]# firewall-cmd --reload

二. 创建用户,并添加密码

使用 root 用户操作

# 创建用户名 为 dangan的用户
[root@localhost ~]# adduser dangan  
# 修改dangan用户的密码
[root@localhost ~]# passwd dangan
#添加权限
[root@localhost ~]# mkdir -p /opt/dangan
[root@localhost ~]# chown -R dangan:dangan /opt/dangan/

三. 编译安装

使用 root 用户操作

  1. 上传解压文件nginx_source.zip
[root@localhost ~]# cd /opt/dangan
# 上传文件到 /opt/dangan 目录中, 执行解压操作
[root@localhost dangan]# unzip nginx_source.zip
[root@localhost ~]# tar -zxvf ./nginx_source/nginx-1.24.0.tar.gz -C /opt/dangan/
[root@localhost ~]# cd /opt/dangan/
[root@localhost dangan]# mv nginx-1.24.0/ nginx

  1. 编译安装

使用 root 用户操作

[root@localhost dangan]# cd nginx/
# 如报错请按照提示安装依赖, 参考 一. 安装依赖
[root@localhost nginx]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module
[root@localhost nginx]# make && make install
  1. 添加环境变量
[root@ip1 nginx]# vi /etc/profile
# 添加下面内容, 并保存
export PATH=$PATH:/usr/local/nginx/sbin
# 更新环境变量
[root@ip1 nginx]# source /etc/profile
  1. 授予权限
[root@ip1 nginx]# chown -R dangan:dangan /opt/dangan/nginx/
[root@ip1 nginx]# chown -R dangan:dangan /usr/local/nginx

四. 修改配置文件

使用 dangan 用户操作

[root@ip1 nginx]# su dangan
[dangan@ip1 nginx]$ cd /usr/local/nginx/conf/

# 修改 nginx.conf 两处地方
[dangan@ip1 conf]$ vi nginx.conf
# 把 2 行的 #user  nobody 修改为 user  dangan;
user  dangan;
# 在 36 行把 listen 80 修改为 8080
listen 8080

五. 开机自启

dangan 用户执行

[dangan@ip1 nginx]$ cd /opt/dangan/nginx/
[dangan@ip1 nginx]$ vi start-nginx.sh
[dangan@ip1 nginx]$ chmod +x start-nginx.sh 

root 用户执行

# root 用户执行
[dangan@ip1 nginx]$ su
密码:
[root@ip1 nginx]# vi /etc/rc.d/rc.local 
# 添加下面配置即可, 保存关闭
su dangan /opt/dangan/nginx/start-nginx.sh
[root@ip1 nginx]# chmod +x /etc/rc.d/rc.local

六. 启动服务

dangan 用户启动

[root@ip1 nginx]# su dangan
[dangan@ip1 ~]$ nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值