Nginx linux部署手册
文档文件 链接地址密码:h3qk
一. 安装前提
描述:
描述 | 名称 | 备注 |
---|---|---|
Nginx 版本 | nginx-1.24.0 稳定版 | |
安装前提依赖 | gcc | yum -y install gcc-c++ |
安装前提依赖 | pcre pcre-devel | yum install -y pcre pcre-devel |
安装前提依赖 | zlib zlib-devel | yum install -y zlib zlib-devel |
安装前提依赖 | openssl openssl-devel | yum 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 用户操作
- 上传解压文件
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
- 编译安装
使用 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
- 添加环境变量
[root@ip1 nginx]# vi /etc/profile
# 添加下面内容, 并保存
export PATH=$PATH:/usr/local/nginx/sbin
# 更新环境变量
[root@ip1 nginx]# source /etc/profile
- 授予权限
[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