• Nginx 丢失Cookies问题。所需的防伪表单字段“__RequestVerificationToken”不存在


    1、所需的防伪表单字段“__RequestVerificationToken”不存在

    1.1 Nginx C# ASP.Net Mvc 丢失cookies 问题。

    1.1.1 解释 underscores_in_headers 配置

    上面图片的意思是 【指示是否传递原始请求的标头字段 到代理服务器。】。

    #PROXY-START/
       # 防止带下划线的cookies丢失。
    
        underscores_in_headers on;
        
    location  /
    {
        proxy_pass http://10.0.8.2:8055/;
        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 REMOTE-HOST $remote_addr;
    
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_cookie_domain 10.0.8.2:8055 10.0.8.100:8055;  
        proxy_http_version 1.1;
        # proxy_hide_header Upgrade;
    
        add_header X-Cache $upstream_cache_status;
    
        #Set Nginx Cache
        
        
        set $static_fileQoRZZHQC 0;
        if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
        {
        	set $static_fileQoRZZHQC 1;
        	expires 1m;
            }
        if ( $static_fileQoRZZHQC = 0 )
        {
        add_header Cache-Control no-cache;
        }
    }
    
    #PROXY-END/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    详解

    Nginx underscores_in_headers 配置详解

    在 Nginx 中,underscores_in_headers 是一个指令,用于控制 Nginx 是否允许在 HTTP 头字段中使用下划线(_)。

    默认情况

    默认情况下,Nginx 不允许在 HTTP 头字段中使用下划线。因为根据 HTTP/1.1 规范,HTTP 头字段的名称应该是由大写字母、小写字母、数字和短划线组成,并且不能包含任何其他字符。因此,如果尝试在 HTTP 头字段中使用下划线,Nginx 会将其视为无效的字段名并忽略该字段。

    启用下划线支持

    然而,在某些情况下,使用下划线可能对于某些扩展 HTTP 头字段是有必要的。在这种情况下,可以使用 underscores_in_headers 指令来启用下划线的支持。

    语法如下:

    underscores_in_headers on;  
    
    • 1

    当设置 underscores_in_headers 为 on 时,Nginx 将允许在 HTTP 头字段中使用下划线。例如,如果设置以下指令:

    underscores_in_headers on;  
    
    • 1

    那么 Nginx 将接受以下 HTTP 头字段:

    Custom-Header: abc  
    X-Another-Header: 123  
    
    • 1
    • 2

    注意

    尽管 Nginx 允许在 HTTP 头字段中使用下划线,但仍然建议遵循 HTTP/1.1 规范,并避免使用下划线作为 HTTP 头字段名称的一部分。这是因为不是所有的 HTTP 客户端和服务端都支持在 HTTP 头字段中使用下划线的配置。因此,使用带有下划线的 HTTP 头字段可能会在某些情况下导致问题。

  • 相关阅读:
    云之道知识付费v1.5.4小程序+前端(含pc付费插件)
    美团二面:如何保证Redis与Mysql双写一致性?连续两个面试问到了!
    静态类+单例模式
    Http状态码502常见原因及排错思路(实战)
    Kafka 实战使用、单机搭建、集群搭建、Kraft集群搭建
    [HDLBits] Fsm2s
    MMDetection代码实战
    前端工程化小记
    用全域安全防范美国NSA对西工大的网络攻击
    大学生学生证教育优惠使用JetBrains全家桶(Pycharm、IDEA、goland等)
  • 原文地址:https://blog.csdn.net/bj_xuzhiqiang/article/details/134079178