NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
LxnChan
V2EX  ›  NGINX

请问一下如何在 nginx 配置层面做到带参数(且参数正确)时返回页面本身内容,否则返回 404?

  •  
  •   LxnChan ·
    lxnchan · Sep 19, 2022 · 2173 views
    This topic created in 1393 days ago, the information mentioned may be changed or developed.

    例如访问https://my.website/aaa.html?para=correct时返回aaa.html的内容,否则跳转到bbb.html

    目前我在配置文件中写了query_string但是感觉会死循环:

    	# Test
    	location ~* ^/aaa.html {
    	#设置 content type
    	default_type text/html ;
    	
    	# HTTP Status Code 和 内容 
    	if ($query_string ~ ".*(?:^|\?|&)para=correct(?:(?:&.*)|$)") { 
    		return 200 /aaa.html; 
    	}
    	return 200  /bbb.html;
        }
    
    5 replies    2022-09-19 15:54:01 +08:00
    julyclyde
        1
    julyclyde  
       Sep 19, 2022
    if ($arg_para=correct)
    julyclyde
        2
    julyclyde  
       Sep 19, 2022
    担心死循环的话,就把逻辑反过来写
    只处理错误的情况,return404 ;正常情况就让 nginx 自己管
    LxnChan
        3
    LxnChan  
    OP
       Sep 19, 2022
    @julyclyde 那请教一下反过来怎么写呢?“!=”吗
    oott123
        4
    oott123  
       Sep 19, 2022
    /t/879586
    我还以为我穿越了
    julyclyde
        5
    julyclyde  
       Sep 19, 2022
    @oott123 诶奇怪,你说的这篇也就几天前,但是前几天我没看到这篇帖子
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5508 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 103ms · UTC 05:55 · PVG 13:55 · LAX 22:55 · JFK 01:55
    ♥ Do have faith in what you're doing.