nginx配置支持ws,并解决跨域

修改配置文件nginx.conf

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
server {
    listen 443 ssl;
    server_name excalidraw.haimaotv.com;
    ssl_certificate /opt/nginx-1.24.0/excalidraw.haimaotv.com_bundle.crt;
    ssl_certificate_key /opt/nginx-1.24.0/excalidraw.haimaotv.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
 
    location / {
     //解决跨域
      if ($request_method = 'OPTIONS') {
               add_header Access-Control-Allow-Origin 'https://ottepg-moss.cedock.com';
               add_header Access-Control-Allow-Headers '*';
               add_header Access-Control-Allow-Methods '*';
               add_header Access-Control-Allow-Credentials 'true';
               return 204;
       }
       if ($request_method != 'OPTIONS') {
           add_header Access-Control-Allow-Origin 'https://ottepg-moss.cedock.com' always;
           add_header Access-Control-Allow-Credentials 'true';
       }
 
       proxy_pass http://127.0.0.1:3002; # 将请求代理转发到本地3002端口的服务
       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 X-Forwarded-Proto $scheme;
       //支持websocket
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_cache_bypass $http_upgrade;
     }
   }

  


__EOF__

本文作者Jun10ng
本文链接https://www.cnblogs.com/wangzun/p/17982942.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   Johnson_wang  阅读(599)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示