添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
傻傻的双杠  ·  Compiling XLA with ...·  1 周前    · 
含蓄的火锅  ·  Java 8 上的 SQL Server ...·  1 周前    · 
深情的鞭炮  ·  Install .NET Runtime ...·  1 周前    · 
小胡子的大葱  ·  Gentoo Forums :: View ...·  6 天前    · 
爽快的绿豆  ·  linux kill命令__linux ...·  4 天前    · 
有腹肌的熊猫  ·  Cannot find the class ...·  1 月前    · 
小眼睛的紫菜  ·  Dialog ...·  2 月前    · 
不爱学习的电梯  ·  Testing - 1.68.0·  4 月前    · 
飞奔的莲藕  ·  北京大学法学院·  5 月前    · 
已拦截跨源请求:同源策略禁止读取位于
 https://one.liuweiqing.top/v1/chat/completions 的远程资源。
(原因:CORS 头 'Access-Control-Allow-Origin' 不匹配 '*, *')。
已拦截跨源请求:同源策略禁止读取位于 https://one.liuweiqing.top/v1/chat/completions 
的远程资源。(原因:CORS 请求未能成功)。状态码:(null)。

我nginx是这么配置的:

        server {
                listen 443 ssl;
                server_name one.liuweiqing.top;
                ssl_certificate /etc/cert/fullchain.pem; #证书位置
                ssl_certificate_key /etc/cert/key.pem; #私钥位置
                ssl_session_timeout 1d;
                ssl_session_cache shared:MozSSL:10m;
                ssl_session_tickets off;
                ssl_protocols TLSv1.2 TLSv1.3;
                ssl_prefer_server_ciphers off;
                location / {
                        proxy_pass http://localhost:3000;
                        proxy_http_version 1.1;
                        proxy_set_header Host $host:$server_port;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                        # 允许跨域的设置
                        add_header 'Access-Control-Allow-Origin' '*' always;
                        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
                        add_header 'Access-Control-Allow-Headers' 'X-Requested-With,Content-Type,X-Token-Auth,Authorization' always;
                        proxy_pass http://localhost:3000;
                        proxy_http_version 1.1;
                        proxy_set_header Host $host:$server_port;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                        # 预检请求
                        if ($request_method = 'OPTIONS') {
                                add_header 'Access-Control-Allow-Origin' "$http_origin";
                                add_header 'Access-Control-Allow-Credentials' 'true';
                                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
                                add_header 'Access-Control-Allow-Headers' '*'; # 允许所有头
                                return 204;
              

上面的配置解决了oneapi的问题,但是没有解决这个网站的问题,继续求助
已拦截跨源请求:同源策略禁止读取位于 https://plus.liuweiqing.top/v1/chat/completions 的远程资源。(原因:CORS 头缺少 ‘Access-Control-Allow-Origin’)。状态码:200。

Error: TypeError: NetworkError when attempting to fetch resource.

        server {
                listen 443 ssl;
                server_name plus.liuweiqing.top;
                ssl_certificate /etc/cert/fullchain.pem; #证书位置
                ssl_certificate_key /etc/cert/key.pem; #私钥位置
                ssl_session_timeout 1d;
                ssl_session_cache shared:MozSSL:10m;
                ssl_session_tickets off;
                ssl_protocols TLSv1.2 TLSv1.3;
                ssl_prefer_server_ciphers off;
                location / {
                        proxy_pass http://localhost:8100;
                        proxy_http_version 1.1;
                        proxy_set_header Host $host:$server_port;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                        # 预检请求
                        if ($request_method = 'OPTIONS') {
                                add_header 'Access-Control-Allow-Origin' "$http_origin";
                                add_header 'Access-Control-Allow-Credentials' 'true';
                                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
                                add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization'; # 显式列出允许的头
                                return 204;
                listen 443 ssl;
                server_name plus.liuweiqing.top;
                ssl_certificate /etc/cert/fullchain.pem; #证书位置
                ssl_certificate_key /etc/cert/key.pem; #私钥位置
                ssl_session_timeout 1d;
                ssl_session_cache shared:MozSSL:10m;
                ssl_session_tickets off;
                ssl_protocols TLSv1.2 TLSv1.3;
                ssl_prefer_server_ciphers off;
                # 添加CORS头部
                add_header 'Access-Control-Allow-Origin' "$http_origin" always;
                add_header 'Access-Control-Allow-Credentials' 'true' always;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
                add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always;
                location / {
                        proxy_pass http://localhost:8100;
                        proxy_http_version 1.1;
                        proxy_set_header Host $host:$server_port;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                        # 预检请求的特殊处理可以保留
                        if ($request_method = 'OPTIONS') {
                                return 204;
这个比较通用它既避免了原始程序在没有处理跨域问题时返回401未授权问题,又添加了对所有响应添加跨域请求的功能