我正在托管自己的TURN-Server,我已将NGINX配置为我的网络服务器。
这是我的问题:
我有一个JavaScript WebRTC客户端需要为ICE Candidates调用转弯服务器,因此我的TURN-Server在40501端口上运行。
不幸的是,在JavaScript中我收到了Cross Origin Request Blocked错误!
这里是寻求NGINX帮助的地方。我将NGINX配置为侦听端口40500并将请求代理到运行我的TURN-Server的端口40501,如下所示:
upstream turn{
server 128.199.xx.xx:40501;
}
server {
listen 40500;
server_name _;
location / {
proxy_pass http://turn;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
}
但它对我没有好处。我无法通过NGINX连接到我的TURN-Sever。我究竟做错了什么? 提前谢谢!