Don';看不出两个nginx配置之间的区别

Don';看不出两个nginx配置之间的区别,nginx,Nginx,伙计们。我需要你的帮助。 第一个配置文件正在成功运行: set $cors ""; if ($http_origin ~* "^https?://auto.*") { set $cors "true"; } if ($http_origin ~* "^https?://dom.*") { set $cors "true"; } location /push/pub/ { push_stream_publisher admin;

伙计们。我需要你的帮助。 第一个配置文件正在成功运行:

set $cors "";
if ($http_origin ~* "^https?://auto.*") {
    set $cors "true";
}
if ($http_origin ~* "^https?://dom.*") {
    set $cors "true";
}
location /push/pub/ {
    push_stream_publisher                   admin;
    push_stream_channels_path               $arg_id;
    include allow/servers.*.conf;
    deny all;
}
location ~ /push/sub/(.*) {
    push_stream_subscriber                  long-polling;
    push_stream_channels_path               $1;
    push_stream_last_received_message_tag   $arg_tag;
    push_stream_last_received_message_time  $arg_time;
    push_stream_longpolling_connection_ttl  30s;
}
#cors configuration
    if ($cors = "true") {
      add_header  'Access-Control-Allow-Origin' "$http_origin";
      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'If-Modified-Since';
    }
}
我试图重构这段代码,并得到类似的东西

location /push/pub/ {
    push_stream_publisher                   admin;
    push_stream_channels_path               $arg_id;
    include allow/servers.*.conf;
    deny all;
}

location ~ /push/sub/(.*) {
    push_stream_subscriber                  long-polling;
    push_stream_channels_path               $1;
    push_stream_last_received_message_tag   $arg_tag;
    push_stream_last_received_message_time  $arg_time;
    push_stream_longpolling_connection_ttl  30s;

    if ($http_origin ~* "^https?://(auto|dom).*") {
        add_header 'Access-Control-Allow-Origin' "$http_origin";
        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'If-Modified-Since';
    }
}
现在你要永远倾听。服务器没有响应:( 两种配置的根本区别是什么?我不明白。
Thx的建议。

不同之处在于,在第二种情况下,
if
指令创建另一个配置上下文,其中您有
add_headers
,但没有配置
push_stream

您应该了解“重写”模块的工作原理(这很棘手): 如果,则尽量避免使用