当前位置: 首页 > news >正文

CentOS7 配置Nginx域名HTTPS

Configuring Nginx with HTTPS on CentOS 7 involves similar steps to the ones for Ubuntu, but with some variations in package management and service control. Here’s a step-by-step guide for CentOS 7:

Prerequisites

  1. Domain Name: “www.xxx.com”
  2. Nginx Installed: Ensure Nginx is installed.
  3. Domain DNS: Domain should point to your server’s IP address.
  4. Root Privileges: You should have root or sudo privileges.
    在这里插入图片描述

Step-by-Step Guide

1. Install Nginx

If Nginx is not already installed, you can install it using the following commands:

sudo yum install epel-release
sudo yum install nginx

Start and enable Nginx to start on boot:

sudo systemctl start nginx
sudo systemctl enable nginx
2. Configure Firewall

Allow HTTPS traffic through your firewall:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
3. Obtain SSL Certificate

Install Certbot and the Nginx plugin:

sudo yum install certbot python2-certbot-nginx
4. Request SSL Certificate

Run Certbot to obtain and install the SSL certificate:

sudo certbot --nginx -d www.xxx.com

Follow the prompts to complete the process. Certbot will automatically configure Nginx to use the SSL certificate.

5. Verify Nginx Configuration

Open your Nginx configuration file to verify or manually configure the SSL settings:

sudo vim /etc/nginx/conf.d/www.xxx.com.conf

Ensure your server block looks like this:

server {listen 80;listen [::]:80;server_name www.xxx.com;return 301 https://$host$request_uri;
}server {listen 443 ssl;listen [::]:443 ssl;server_name www.xxx.com;ssl_certificate /etc/letsencrypt/live/www.xxx.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;include /etc/letsencrypt/options-ssl-nginx.conf;ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;root /usr/share/nginx/html;index index.html index.htm;location / {try_files $uri $uri/ =404;}
}
6. Test Nginx Configuration

Test your configuration to ensure there are no syntax errors:

sudo nginx -t

If the test is successful, reload Nginx:

sudo systemctl reload nginx
7. Set Up Automatic Certificate Renewal

Let’s Encrypt certificates are valid for 90 days. Certbot can handle renewal automatically. To set up a cron job for automatic renewal, open the crontab editor:

sudo crontab -e

Add the following line to the crontab file:

0 0,12 * * * /usr/bin/certbot renew --quiet

This runs the renewal command twice daily.

Access Your Site

Now, you should be able to access your site securely at https://www.xxx.com.

Troubleshooting

If you encounter any issues, check the Nginx and Certbot logs for more information:

sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/letsencrypt/letsencrypt.log

This setup ensures that your website is served over HTTPS, providing security and trust to your visitors.

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • React@16.x(23)useEffect
  • [ue5]建模场景学习笔记(5)——必修内容可交互的地形,交互沙(3)
  • Spring Boot 深度学习笔记:从入门到精通的全面指南
  • 【报文数据流中的反压处理】
  • CleanMyMac2024最新免费电脑Mac系统优化工具
  • SQL Server中的CTE和临时表优化
  • C语言 | Leetcode C语言题解之第140题单词拆分II
  • CMakeLists如何多行注释
  • 计算机毕业设计python+spark知识图谱音乐推荐系统 音乐数据分析可视化大屏 音乐爬虫 LSTM情感分析 大数据毕设 深度学习 机器学习
  • RoLabelImg下载及旋转目标检测数据标注
  • Linux | buildrootfs 添加mkfs.ext3/mkfs.ext4 支持
  • 【算法小记】深度学习——时间序列数据分析 Time series Data Analysis
  • C#操作MySQL从入门到精通(17)——使用联结
  • Android AOSP定制去掉Google搜索栏
  • 单词记忆(第二周)
  • 【108天】Java——《Head First Java》笔记(第1-4章)
  • 2017-08-04 前端日报
  • express.js的介绍及使用
  • Java面向对象及其三大特征
  • mysql_config not found
  • Service Worker
  • windows-nginx-https-本地配置
  • 关于List、List?、ListObject的区别
  • 官方解决所有 npm 全局安装权限问题
  • 前言-如何学习区块链
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • RDS-Mysql 物理备份恢复到本地数据库上
  • ​【原创】基于SSM的酒店预约管理系统(酒店管理系统毕业设计)
  • ​LeetCode解法汇总518. 零钱兑换 II
  • ​埃文科技受邀出席2024 “数据要素×”生态大会​
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • ### RabbitMQ五种工作模式:
  • #APPINVENTOR学习记录
  • #C++ 智能指针 std::unique_ptr 、std::shared_ptr 和 std::weak_ptr
  • #HarmonyOS:Web组件的使用
  • (3)Dubbo启动时qos-server can not bind localhost22222错误解决
  • (4)logging(日志模块)
  • (7)摄像机和云台
  • (补充):java各种进制、原码、反码、补码和文本、图像、音频在计算机中的存储方式
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (五)关系数据库标准语言SQL
  • (小白学Java)Java简介和基本配置
  • (一)utf8mb4_general_ci 和 utf8mb4_unicode_ci 适用排序和比较规则场景
  • .NET MVC、 WebAPI、 WebService【ws】、NVVM、WCF、Remoting
  • .net 设置默认首页
  • .net 无限分类
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @Transactional 详解
  • [Android实例] 保持屏幕长亮的两种方法 [转]
  • [BUG] Hadoop-3.3.4集群yarn管理页面子队列不显示任务
  • [Bug]使用gradio创建应用提示AttributeError: module ‘gradio‘ has no attribute ‘inputs‘
  • [bzoj4010][HNOI2015]菜肴制作_贪心_拓扑排序
  • [C++]二叉搜索树
  • [CF703D]Mishka and Interesting sum/[BZOJ5476]位运算
  • [codevs 2822] 爱在心中 【tarjan 算法】