Solve CORS Issues Easily with Nginx Reverse Proxy – No JSONP Needed

This guide explains how to bypass cross‑origin restrictions by configuring an Nginx reverse proxy, offering a simpler alternative to JSONP that avoids server‑side code changes while enabling seamless API calls from a different domain.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Solve CORS Issues Easily with Nginx Reverse Proxy – No JSONP Needed

Cross‑origin requests can be handled with JSONP, but it requires modifying the server side code, which is cumbersome.

By configuring a reverse proxy on your own server with Nginx, you can easily achieve cross‑origin requests without changing the target server.

Idea

Example

Server A has a page that wants to request the API at Server B (http://www.b.com/api) and obtain JSON data.

Page code on Server A:

<script>
$(function (){
  $.get('/test.do', function (data){
    alert(data);
  });
});
</script>

Configure Nginx to proxy /test.do to the target API:

location /test.do {
  proxy_pass http://www.b.com/api;
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CORSNginxJSONP
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.