【发布时间】:2020-01-12 20:12:42
【问题描述】:
伙计们。我需要你的帮助。 第一个配置文件运行成功:
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';
}
}
现在 js 订阅者永远聆听。服务器没有响应:( 两个配置之间的根本区别是什么。我不明白。 谢谢建议。
【问题讨论】:
标签: nginx