nginx解决前端跨域问题

server {
        listen       8090;
        server_name  localhost;
        location / {
            root /Users/xxx/Desktop/localNginxSpace;
            autoindex on;
            #index index.html index.htm;
        }
        location /xxx-xxx {
            proxy_pass http://xxx.xxx.xxx.xxx:40094/;
            #add_header Access-Control-Allow-Methods "POST, GET";
        }
    }

有个本地的html文件,ajax请求接口,nginx配置如上,访问localhost:8090还是存在跨域问题

阅读 2.6k
2 个回答
server {
        listen       8088;
    server_name  localhost;
    location / {
        #本地文件路径
        root /Users/XXX/Desktop/localNginxSpace;
        autoindex on;
    }
        #需要代理的接口地址(/api)
    location /xxxx-xxxx {
        proxy_pass http://xxx.xxx.xxx.xxx:8080/;
        }
    }

前端请求地址:

http://localhost:8088/xxxx-xxxx/···

你可以看看这篇文章前端如何解决跨域问题

你可以提供下你需要访问的地址,以及你前端怎么访问的,信息详细些,根据你的上述问题无法排查出阿里

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题