In my nginx server block I have allowed access but I still get the message:
Access to XMLHttpRequest at 'http://api.mywebsite.com/tags/' from origin 'http://mywebsite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is how my server block looks like:
server {
listen 80;
server_name mywebsite.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
add_header Access-Control-Allow-Origin mywebsite.com;
}
server {
listen 80;
server_name api.mywebsite.com;
add_header Access-Control-Allow-Origin mywebsite.com;
root /mywebsite/api/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php = 404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Anyone know what I have done wrong? Or what I have to do to allow requests to subdomains?
Access to XMLHttpRequest at 'http://api.mywebsite.com/tags/' from origin 'http://mywebsite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is how my server block looks like:
server {
listen 80;
server_name mywebsite.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
add_header Access-Control-Allow-Origin mywebsite.com;
}
server {
listen 80;
server_name api.mywebsite.com;
add_header Access-Control-Allow-Origin mywebsite.com;
root /mywebsite/api/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php = 404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Anyone know what I have done wrong? Or what I have to do to allow requests to subdomains?