Thursday, January 18, 2018

How to enable CORS in Nginx

I have tried every tutorial on the internet and on serverfault regarding this. No matter what I do, CORS is not working in nginx




Here is my example.conf




server {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name www.arcadesite.io arcadesite.io;

    location = /favicon.ico { log_not_found off; access_log off; }

location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}


location / {
try_files $uri $uri/ /index.php$is_args$args;
add_header Access-Control-Allow-Origin *;

}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}


location ~* \.(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}


listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/arcadesite.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/arcadesite.io/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;


include rocket-nginx/default.conf;



}
server {
if ($host = www.arcadesite.io) {
return 301 https://$host$request_uri;
}




if ($host = arcadesite.io) {
return 301 https://$host$request_uri;
}


listen 80;
server_name www.arcadesite.io arcadesite.io;
return 404;include rocket-nginx/default.conf;}

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...