要解决Nginx的跨域问题,可以采取以下几种方法:
location / { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } } location /api/ { proxy_pass http://backend-server; } location / { proxy_pass http://backend-server:8080; } 以上是一些常见的解决Nginx跨域问题的方法,根据实际情况选择合适的方法进行配置。