fjykTec / ModernWMS

The open source simple and complete warehouse management system is derived from our many years of experience in implementing erp projects. We stripped the original commercial system wms function and opened it up for free, hoping to help the majority of small and medium-sized enterprises. At present, the system supports cross-platform。
https://modernwms.ikeyly.com/
Apache License 2.0
821 stars 259 forks source link

非80端口的跨域问题 Request Timeout #15

Closed fduxuan closed 1 year ago

fduxuan commented 1 year ago

部署到服务器上时使用nginx设置域名:

server {
    listen 80;
    server_name xxx.com;
    return 301 https://$server_name$request_uri;

}
server {
    keepalive_requests 120; #单连接请求上限次数。
    listen 443 ssl;   #监听端口
    ssl_certificate /etc/letsencrypt/live/xxx.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xxx.com/privkey.pem;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    server_name  xxx.com;   #监听地址
    proxy_set_header X-Real_IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X_Forward_For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;   #需要配置支持websocket
    proxy_set_header Connection 'upgrade';    #需要配置支持websocket

    # 允许跨域请求的域, * 表示所有
add_header 'Access-Control-Allow-Origin' *;
# 允许携带Cookie
add_header 'Access-Control-Allow-Credentials' 'true';
# 允许请求的方式 比如常用的Restful GET/PUT/POST/DELETE
add_header 'Access-Control-Allow-Methods' *;
# 允许请求的header
add_header 'Access-Control-Allow-Headers' *;
    #add_header Access-Control-Allow-Origin *;
    #add_header Access-Control-Allow-Credentials true;
    root /tmp/ModernWMS-master/docker/frontend;
    location  / {
       index    index.html;    #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
    }
    location /assets{
        alias /tmp/ModernWMS-master/docker/frontend/assets;
    }
}

此时后端采用普通启动: dotnet ModernWMS.dll --urls http://0.0.0.0:20011

用postman检查后端正常: image

检查前端正常: image

前端发送请求遭遇跨域问题: image

已经在nginx配置了允许,依然会出现这样的问题,有什么解决办法吗?

fduxuan commented 1 year ago

已经解决,把前端request改一个固定前缀再用nginx rewrite

RayRuiXu commented 5 months ago

已经解决,把前端request改一个固定前缀再用nginx rewrite

作者你好,我在部署到阿里云ECS服务器的时候,遇到了同样的问题,能请您详细说一下您的解决办法吗?谢谢!