一、该问题的重现步骤是什么?
1. 部署Rider到线上后,如跳过登录直接访问,会请求报错,请求跨域问题,有什么办法可以在未登录的情况下,拦截跳转到登录页面吗,前端已拦截,但是没有生效,同样的代码在本地运行正常;另外如果没有配置白名单放行,即使登录之后请求接口还是会报跨域错误,但是token是有效的(所有的问题在本地都运行正常)
2. 报错信息:Access to XMLHttpRequest at 'http://xxx/app/blade-message/message/my/NotReadlist' from origin 'http://xxx' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
3.后端已配置跨域
4.前端已拦截401请求,跳转登录页面,这段代码在本地生效,部署到线上后,没有走到这里,测试异常没有打印
5.请求报错截图,会发送两次请求
6.nginx配置:
user www www;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
#include luawaf.conf;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server
{
listen 80;
server_name xxx;
#index index.html index.htm index.php;
#root /www/server/phpmyadmin;
#error_page 404 /404.html;
#include enable-php.conf;
location /app {
proxy_pass http://xxx:88;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
if ($request_method = OPTIONS){
return 200;
}
}
location / {
root /www/server/nginx/Rider;
index index.html;
try_files $uri $uri/ /index.html;
proxy_pass http://xxx:88;
}
access_log /www/wwwlogs/access.log;
}
include /www/server/panel/vhost/nginx/*.conf;
}
二、你期待的结果是什么?实际看到的又是什么?
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
四、请提供详细的错误堆栈信息,这很重要。
五、若有更多详细信息,请在下面提供。
扫一扫访问 Blade技术社区 移动端