Set up nginx to allow cross-domain request for subdomain
cross-domain, nginx
Solution
I think you need to create this inside the location or server block
server {
server_name example.com;
add_header Access-Control-Allow-Origin sub.example.com; # < this is the needed header
# rest of the configuration
}
Problem
I've got two domains: domain.com sub.domain.com domain.com needs to make an ajax request to sub.domain.com. I realize that the browser will block this if the request is hardcoded to be sub.domain.com. I tried the following nginx conf: ``` server { server_name domain.com; rewrite ^/api/(.*)$ http://sub.domain.com/api/$1; } ``` However, I still get the following error in the browser (Chrome): ``` No 'Access-Control-Allow-Origin' header is present on the requested resource. ``` How can I set up nginx to instruct the browser to allow cross domain requests between domain.com and sub.domain.com? Thanks!