15 Eylül 2020 07:59

Doğancan A.

Nginx

NGINX proxy ile CORS ayarları nasıl yapılır? CORS hatası çözümü.

Anasayfa

Nginx

NGINX proxy ile CORS ayarları nasıl yapılır? CORS ...

 

NGINX proxy ile CORS ayarları nasıl yapılır? NGINX  CORS hatası çözümü.

 

server {
  listen 80;
  server_name api.alanadi.com;
  return 301 https://$host$request_uri;
}


server {

  listen 443;
  ssl on;
  ssl_certificate /etc/letsencrypt/live/alanadi.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/alanadi.com/privkey.pem;
  access_log off;
  server_tokens off;
  error_log /tmp/log_nginx_err_apialanadicom.log debug;
  root /home/ubuntu/api_alanadicom/;

location / {
  add_header 'Access-Control-Allow-Origin' '*';
  add_header 'Access-Control-Allow-Credentials' 'true';
  add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
  add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';

if ($request_method = 'OPTIONS') {
  return 204;
}

proxy_redirect off;
proxy_set_header Host '\$http_host';
proxy_set_header X-Forwarded-For '\$proxy_add_x_forwarded_for';
proxy_set_header X-Forwarded-Proto '\$http_x_forwarded_proto';
proxy_pass http://0.0.0.0:8000;
}


location /ws {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
proxy_pass http://0.0.0.0:8000;
}


}
 
nginx -t
systemctl restart nginx
   

Makdos Bilişim Teknolojileri 2015 - 2025