十二 nginx中location重写和匹配规则

2024-06-11 22:36

本文主要是介绍十二 nginx中location重写和匹配规则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

十二 location匹配规则 
= ^~ ~ ~*  !~ !~* /a   / @
@内部服务跳转

十三 nginx地址重写rewrite
if rewrite set return 

13.1 if 应用环境 
server location

-x  文件是否可执行 
$args  
$document_rot
$host
$limit_rate 
$remote_addr 
$server_name 
$document_uri  

if (coduction) {
... 
 }

13.2 rewrite  flag  
last     
break     本条匹配完成后 终止匹配
redirect     302  临时重定向 
permanent   301  永久重定向 

80 http
443 https  

案例1
修改前:http://www.dadishu.com/a/index.html 
修改后:http://www.dadishu.com/b/index.html
server   {
      listen 80;
      server_name www.dadishu.com;
location / {
       root   /data/wwwroot 
       index index.html
      }
location /a {
    root /html; 
    index   index.html;
   rewrite  .* /b/2.html permanent;
}
location /b {
    root /html; 
    index  index.html;
}
}

案例2 
http://www.testpm.com/2019/a/index.html 
http://www.testpm.com/2018/a/index.html
location /2019/a {
    root     /html;
    index  index.html;
    rewrite ^/2019/(.*)$ /2018/$1  permanent; 
}
location /2018/a {
    root /html;
    index  index.html;
}

案例三 核心
http://www.qf.com/a/1.html   http://jd.com 
location /a  {
    root /html;
    if ($host ~* www.qf.com) {
    rewrite .* http//jd.com permanent;
    }
}

案例四 
http://www.qf.com/a/1.html  http://jd.com/a/1.html 

location /a {
    root /html;
    if ($host ~* qf.com){
rewrite .* http://jd.com$request_uri permanent;
    }
}

案例五 
修改前:http//www.tianyun.com/login/tianyun.html 
修改后:http://www.tianyun.com/reg/login.html?user=tianyun
location /login {
    root /usr/share/nginx/html;
    rewrite ^/login/(.*)\.html$ http://$host/reg/login.html?user=$1;

location /reg {
root /usr/share/nginx/html;
index login.html;    
}

13.3  set指令 
应用环境 server location if 

13.4 return  
server location if 


 

这篇关于十二 nginx中location重写和匹配规则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

Nginx中配置使用非默认80端口进行服务的完整指南

《Nginx中配置使用非默认80端口进行服务的完整指南》在实际生产环境中,我们经常需要将Nginx配置在其他端口上运行,本文将详细介绍如何在Nginx中配置使用非默认端口进行服务,希望对大家有所帮助... 目录一、为什么需要使用非默认端口二、配置Nginx使用非默认端口的基本方法2.1 修改listen指令

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

SpringBoot3匹配Mybatis3的错误与解决方案

《SpringBoot3匹配Mybatis3的错误与解决方案》文章指出SpringBoot3与MyBatis3兼容性问题,因未更新MyBatis-Plus依赖至SpringBoot3专用坐标,导致类冲... 目录SpringBoot3匹配MyBATis3的错误与解决mybatis在SpringBoot3如果

Nginx添加内置模块过程

《Nginx添加内置模块过程》文章指导如何检查并添加Nginx的with-http_gzip_static模块:确认该模块未默认安装后,需下载同版本源码重新编译,备份替换原有二进制文件,最后重启服务验... 目录1、查看Nginx已编辑的模块2、Nginx官网查看内置模块3、停止Nginx服务4、Nginx

Spring Security重写AuthenticationManager实现账号密码登录或者手机号码登录

《SpringSecurity重写AuthenticationManager实现账号密码登录或者手机号码登录》本文主要介绍了SpringSecurity重写AuthenticationManage... 目录一、创建自定义认证提供者CustomAuthenticationProvider二、创建认证业务Us

通过配置nginx访问服务器静态资源的过程

《通过配置nginx访问服务器静态资源的过程》文章介绍了图片存储路径设置、Nginx服务器配置及通过http://192.168.206.170:8007/a.png访问图片的方法,涵盖图片管理与服务... 目录1.图片存储路径2.nginx配置3.访问图片方式总结1.图片存储路径2.nginx配置

Nginx禁用TLSv1.0 1.1改为TLSv1.2 1.3的操作方法

《Nginx禁用TLSv1.01.1改为TLSv1.21.3的操作方法》使用MozillaSSL配置工具生成配置,修改nginx.conf的ssl_protocols和ssl_ciphers,通... 目录方法一:方法二:使用 MoziChina编程lla 提供的 在线生成SSL配置工具,根据自己的环境填充对应的

nginx配置错误日志的实现步骤

《nginx配置错误日志的实现步骤》配置nginx代理过程中,如果出现错误,需要看日志,可以把nginx日志配置出来,以便快速定位日志问题,下面就来介绍一下nginx配置错误日志的实现步骤,感兴趣的可... 目录前言nginx配置错误日志总结前言在配置nginx代理过程中,如果出现错误,需要看日志,可以把

Nginx进行平滑升级的实战指南(不中断服务版本更新)

《Nginx进行平滑升级的实战指南(不中断服务版本更新)》Nginx的平滑升级(也称为热升级)是一种在不停止服务的情况下更新Nginx版本或添加模块的方法,这种升级方式确保了服务的高可用性,避免了因升... 目录一.下载并编译新版Nginx1.下载解压2.编译二.替换可执行文件,并平滑升级1.替换可执行文件