Skip to content

Instantly share code, notes, and snippets.

@Rajeshr34
Last active November 4, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rajeshr34/c7289158458c6e80934853bf95326267 to your computer and use it in GitHub Desktop.
Save Rajeshr34/c7289158458c6e80934853bf95326267 to your computer and use it in GitHub Desktop.
cors
#location ~ \.php$ {
# try_files $uri =404;
# fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
# fastcgi_index /index.php;
# include fastcgi_params;
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#
# include /etc/nginx/sites-available/_cors;
#}
set $methods "'GET, POST, DELETE, PUT, OTPIONS'";
set $headers "'DNT,X-CustomHeader,Keep-Alive,User-Agent,xToken,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'";
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' $methods;
add_header 'Access-Control-Allow-Headers' $headers;
add_header 'Access-Control-Expose-Headers' $headers;
}
if ($request_method = 'PUT') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' $methods;
add_header 'Access-Control-Allow-Headers' $headers;
add_header 'Access-Control-Expose-Headers' $headers;
}
if ($request_method = 'DELETE') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' $methods;
add_header 'Access-Control-Allow-Headers' $headers;
add_header 'Access-Control-Expose-Headers' $headers;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' $methods;
add_header 'Access-Control-Allow-Headers' $headers;
add_header 'Access-Control-Expose-Headers' $headers;
}
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' $methods;
add_header 'Access-Control-Allow-Headers' $headers;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment