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

https nginx 负载均衡配置

我的系统是OpenEuler。

  • 安装nginx
yum install -y nginx
  • 启动&开机启动
systemctl start nginx
systemctl enable nginx
  • 自定义conf配置文件
cat <<EOF >> /etc/nginx/conf.d/load_balancer.conf
upstream backend {ip_hash; # 防止验证码验证失败server 192.168.1.150:443;server 192.168.1.153:443;
}server {listen 80;# 使用 IP 地址作为 server_nameserver_name 192.168.1.155;# 将 HTTP 请求重定向到 HTTPSreturn 301 https://$host$request_uri;# 日志配置access_log /var/log/nginx/192.168.1.155_http_access.log;error_log /var/log/nginx/192.168.1.155_http_error.log;
}server {listen 443 ssl;# 使用 IP 地址作为 server_nameserver_name 192.168.1.155;# SSL 证书配置,使用自签名证书ssl_certificate /opt/crt/server.crt;ssl_certificate_key /opt/crt/server.key;# SSL 优化配置ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;ssl_prefer_server_ciphers on;# 日志配置access_log /var/log/nginx/192.168.1.155_https_access.log;error_log /var/log/nginx/192.168.1.155_https_error.log;# 错误处理配置error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /404.html {root /usr/share/nginx/html;}location = /50x.html {root /usr/share/nginx/html;}location / {proxy_pass https://backend;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;# 处理 HTTPS 相关配置proxy_ssl_server_name on;}
}
EOF
  • 检查配置文件的语法是否正确
nginx -t
  • 重新加载 Nginx 配置 
nginx -s reload
  • OpenSSL 生成自签名证书
openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048openssl req -new -key server.key -out server.csr #【这一步建议绑定ip】openssl x509 -req -in server.csr -signkey server.key -out server.crt -days 36500
  • 开启443端口 
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
  • 验证 
curl -k https://192.168.1.155

    相关文章:

  1. OpenCV 图形API(61)图像特征检测------检测图像边缘的函数Canny()
  2. Qt5.15.2+OpenCV4.9.0开发环境搭建详细图文教程(OpenCV使用Qt自带MinGW编译的全过程,包教包会)
  3. AWS 中国区 CloudFront SSL 证书到期更换实战指南
  4. 第六章 QT基础:5、QT的UDP网络编程
  5. 详解Linux中的定时任务管理工具crond
  6. 使用 Node、Express 和 MongoDB 构建一个项目工程
  7. FastMCP与FastAPI:构建自定义MCP服务器
  8. 入门 Go 语言
  9. Java 2025 技术全景与实战指南:从新特性到架构革新
  10. 十分钟恢复服务器攻击——群联AI云防护系统实战
  11. LLMind:利用大型语言模型协调人工智能与物联网以执行复杂任务
  12. 全行业软件定制:APP/小程序/系统开发与物联网解决方案
  13. 面阵相机中M12镜头和远心镜头的区别及性能优势
  14. Linux下编译opencv-4.10.0(静态链接库和动态链接库)
  15. Vivado版本升级后AXI4-Stream Data FIFO端口变化
  16. centos7使用yum快速安装最新版本Jenkins-2.462.3
  17. IDEA将本地的JAR文件手动安装到 Maven的本地仓库
  18. AI日报 - 2025年04月25日
  19. 数据库day-07
  20. VS Code 智能代理模式:重塑开发体验
  21. 影子调查丨掉落的喷淋头:太原一7天酒店加盟店消防设施造假迷局
  22. 爱奇艺要转型做微剧?龚宇:是误解,微剧是增量业务,要提高投资回报效益
  23. 五一节,和人民照相馆一起找回“拍照”的仪式感
  24. 海南陵水一酒店保洁员调包住客港币,被判刑一年六个月
  25. 校友伉俪捐赠10亿元!成立复旦大学学敏高等研究院
  26. 董明珠卸任格力电器总裁,张伟接棒