【发布时间】:2018-10-12 03:19:37
【问题描述】:
我已经在 nginx 中设置了代理,并在 tomcat 中设置了 web socket 服务器
如果我向http://MY_URL/api/ws/data 发出请求,端口应该从 80 更改为 8060 还有,那些finally必须是https
/etc/nginx/conf.d/default.conf(我使用的是default.conf)
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
add_header Access-Control-Allow-Origin *;
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://localhost:8080;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location /api/ws/data/ {
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-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8060;
proxy_redirect off;
proxy_read_timeout 86400;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
什么时候,我在本地服务器发出请求
无法加载 http://MY_URL/api/ws/data/info?t=1525237291534:从“http://MY_URL/api/ws/data/info?t=1525237291534”重定向到“https://MY_URL/api/ws/data/info?t=1525237291534”已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头.因此不允许访问 Origin 'http://localhost:3000'。
如何在 nginx 中设置 websocket 代理和 cors?
++++
使用 --disable-web-security 命令执行此 chrome 后,
错误请求
主机和端口的这种组合需要 TLS。
是什么意思呢?以及如何解决这个问题?
【问题讨论】:
-
P.S.它已经在 aws cloud front 中设置了 ssl 重定向
标签: ssl nginx proxy server cors