【开端】 进行页面升级或维护时不影响用户体验NGINX配置

2024-08-28 09:04

本文主要是介绍【开端】 进行页面升级或维护时不影响用户体验NGINX配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、绪论
  在网站管理中,经常需要进行页面升级或维护,而为了不影响用户体验,我们可以设置一个访问页面,在页面升级期间,用户访问网站时会直接跳转到该页面。本文将介绍如何设置访问页面进行升级,以确保用户的顺畅访问和良好体验。

二、NGINX配置

首先,创建一个包含维护信息的 HTML 文件,比如 maintenance.html

<!-- maintenance.html -->
<!DOCTYPE html>
<html>
<head><title>维护通知</title>
</head>
<body><h1>系统维护中</h1><p>系统正在维护,敬请期待。</p>
</body>
</html>

接下来,配置 NGINX 使得所有请求都重定向到这个维护页面

# /etc/nginx/nginx.conf 或相应的 NGINX 配置文件
 
server {
    listen 80;
    server_name yourdomain.com;
 
    location / {
        # 重定向所有请求到维护页面
        return 503;
        rewrite ^(.*)$ /maintenance.html break;
    }
 
    location = /maintenance.html {
        # 维护页面的位置
        root /path/to/your/html/files;
        internal;
    }
}

# /etc/nginx/nginx.conf 或相应的 NGINX 配置文件server {listen 80;server_name yourdomain.com;location / {# 重定向所有请求到维护页面return 503;rewrite ^(.*)$ /maintenance.html break;}location = /maintenance.html {# 维护页面的位置root /path/to/your/html/files;internal;}
}

三、nginx的其他配置

nginx.conf

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {# root   html;#index  index.html index.htm;xproxy_pass   http://127.0.0.1:9090;	#代理地址proxy_set_header  Host $host;proxy_set_header   X-real-ip $remote_addr;proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}#  HTTPS server配置server {listen       443 ssl;server_name  localhost;ssl			 on;	#开启SSLclient_max_body_size   0; #设置 不限制 文件上传大小,默认为1M charset utf-8;ssl_certificate      /usr/local/ca/local.crt;	#证书绝对路径ssl_certificate_key  /usr/local/ca/local.key;	#密钥绝对路径ssl_session_cache    shared:SSL:10m;	#设置会话缓存大小ssl_session_timeout  10m;	# 连接超时时间# ssl_ciphers  HIGH:!aNULL:!MD5;	#支持的算法,默认为OpenSSL的全部算法ssl_prefer_server_ciphers  on; #优先使用服务端的SSL密钥证书,默认为off location / {proxy_pass   http://127.0.0.1:8080;proxy_set_header  Host $host;proxy_set_header   X-real-ip $remote_addr;proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;}}    }

限制IP的频繁访问

http {

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=20r/s;//同一个IP每秒20次请求

}

http
{limit_req_zone $binary_remote_addr zone=mylimit:10m rate=20r/s;//同一个IP每秒20次请求
}

配置只能通过域名访问

server {

listen 80 default_server; server_name _; # _ 表示无效域名 location / {

return 403;

}

}

server {listen 80 default_server;	server_name _;	# _ 表示无效域名location / {return 403;}
}

这篇关于【开端】 进行页面升级或维护时不影响用户体验NGINX配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1114324

相关文章

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

Python进行JSON和Excel文件转换处理指南

《Python进行JSON和Excel文件转换处理指南》在数据交换与系统集成中,JSON与Excel是两种极为常见的数据格式,本文将介绍如何使用Python实现将JSON转换为格式化的Excel文件,... 目录将 jsON 导入为格式化 Excel将 Excel 导出为结构化 JSON处理嵌套 JSON:

Debian系和Redhat系防火墙配置方式

《Debian系和Redhat系防火墙配置方式》文章对比了Debian系UFW和Redhat系Firewalld防火墙的安装、启用禁用、端口管理、规则查看及注意事项,强调SSH端口需开放、规则持久化,... 目录Debian系UFW防火墙1. 安装2. 启用与禁用3. 基本命令4. 注意事项5. 示例配置R

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

最新Spring Security的基于内存用户认证方式

《最新SpringSecurity的基于内存用户认证方式》本文讲解SpringSecurity内存认证配置,适用于开发、测试等场景,通过代码创建用户及权限管理,支持密码加密,虽简单但不持久化,生产环... 目录1. 前言2. 因何选择内存认证?3. 基础配置实战❶ 创建Spring Security配置文件

PyCharm中配置PyQt的实现步骤

《PyCharm中配置PyQt的实现步骤》PyCharm是JetBrains推出的一款强大的PythonIDE,结合PyQt可以进行pythion高效开发桌面GUI应用程序,本文就来介绍一下PyCha... 目录1. 安装China编程PyQt1.PyQt 核心组件2. 基础 PyQt 应用程序结构3. 使用 Q

Redis MCP 安装与配置指南

《RedisMCP安装与配置指南》本文将详细介绍如何安装和配置RedisMCP,包括快速启动、源码安装、Docker安装、以及相关的配置参数和环境变量设置,感兴趣的朋友一起看看吧... 目录一、Redis MCP 简介二、安www.chinasem.cn装 Redis MCP 服务2.1 快速启动(推荐)2.

Spring Boot配置和使用两个数据源的实现步骤

《SpringBoot配置和使用两个数据源的实现步骤》本文详解SpringBoot配置双数据源方法,包含配置文件设置、Bean创建、事务管理器配置及@Qualifier注解使用,强调主数据源标记、代... 目录Spring Boot配置和使用两个数据源技术背景实现步骤1. 配置数据源信息2. 创建数据源Be

一文解密Python进行监控进程的黑科技

《一文解密Python进行监控进程的黑科技》在计算机系统管理和应用性能优化中,监控进程的CPU、内存和IO使用率是非常重要的任务,下面我们就来讲讲如何Python写一个简单使用的监控进程的工具吧... 目录准备工作监控CPU使用率监控内存使用率监控IO使用率小工具代码整合在计算机系统管理和应用性能优化中,监

Spring Boot Maven 插件如何构建可执行 JAR 的核心配置

《SpringBootMaven插件如何构建可执行JAR的核心配置》SpringBoot核心Maven插件,用于生成可执行JAR/WAR,内置服务器简化部署,支持热部署、多环境配置及依赖管理... 目录前言一、插件的核心功能与目标1.1 插件的定位1.2 插件的 Goals(目标)1.3 插件定位1.4 核