Nginx
1 前言
一个问题,一篇文章,一出故事。
笔者需要基于RHEL 9部署Nginx环境,于是整理此文。
2 最佳实践
2.1 系统环境
OS = RHEL 9.x x86_64
IP Addresses = 10.168.0.80
Host Name = www.cmdschool.org
2.2 准备工作
2.2.1 配置防火墙
firewall-cmd --permanent --add-service http --add-service https firewall-cmd --reload firewall-cmd --list-all
2.2.2 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
2.2.3 配置时区
timedatectl set-timezone Asia/Shanghai
2.2.4 安装常用工具
yum install -y vim
2.3 部署Nginx服务
2.3.1 配置安装源
vim /etc/yum.repos.d/nginx-rhel9.repo
加入如下配置,
[nginx] name=nginx baseurl=http://nginx.org/packages/centos/9/$basearch/ gpgcheck=1 gpgkey=http://nginx.org/packages/keys/nginx_signing.key
注:其他版本或系统的源请参阅以下链接,
http://nginx.org/packages/
2.3.2 安装软件包
yum install -y nginx
安装完成后,你可以使用如下命令验证安装,
nginx -v
可见如下显示,
nginx version: nginx/1.24.0
2.3.3 启动服务并配置自启动
systemctl start nginx.service systemctl enable nginx.service systemctl status nginx.service
2.4 配置Nginx
2.4.1 创建应用程序目录
mkdir -p /var/www/www.cmdschool.org
2.4.2 配置http虚拟服务器
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/www.cmdschool.org_80.conf vim /etc/nginx/conf.d/www.cmdschool.org_80.conf
保留以下内容:
server { listen 80; server_name www.cmdschool.org; location / { root /var/www/www.cmdschool.org; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
2.4.3 配置https虚拟服务器(可选)
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/www.cmdschool.org_443.conf vim /etc/nginx/conf.d/www.cmdschool.org_443.conf
确认存在如下内容:
server { listen 443; server_name www.cmdschool.org; ssl on; ssl_certificate 1_www.cmdschool.org_bundle.crt; ssl_certificate_key 2_www.cmdschool.org.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; location / { root /var/www/www.cmdschool.org; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
证书请自行申请,这里不详述, 配置完成后,你需要重载服务使配置生效,
systemctl restart nginx.service
2.5 测试服务
2.5.1 创建测试页
echo www.cmdschool.org > /var/www/www.cmdschool.org/index.html
2.5.2 配置名称解析
notepad \Windows\System32\drivers\etc\hosts
增加以下内容,
10.168.0.80 www.cmdschool.org
注:以上仅适用于测试环境的Windows客户端,生产环境请使用DNS实现,Linux客户端请使用如下命令,
echo '10.168.0.80 www.cmdschool.org' >> /etc/hosts
2.5.3 测试虚拟服务
http://www.cmdschool.org
https://www.cmdschool.org
参阅文档
===================
https://nextcloud.com/support/
Nginx
——————-
https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
没有评论