mardi 31 mars 2020

Cors issue when using laravel nginx

I have 2 applications api & front. I'm using laravel + nginx

server {
server_name api.website.com;
root /laravel/public;
listen 80;

error_page 401 403 404 500 502 503 504 /500.html;

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
    fastcgi_pass php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_read_timeout 300;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PATCH, PUT, DELETE, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Content-Type, Accept, Authorization, X-Requested-With, Application';
        return 204;
    }
}

client_max_body_size 64M;

error_log /var/log/nginx/wooxo_api_error.log;
access_log /var/log/nginx/wooxo_api_access.log;
}

server {
#listen 443 ssl http2;
listen 80;
root /laravel/angular/dist;
server_name app.website.com;
index index.html;

location ^~ / {
    try_files $uri /index.html;
    root /laravel/angular/dist/dist;
}

}

But I have the error : (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Can you help me please ? Have no idea. It seems to be a problem with headers. Thank you in advance and sorry for english.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UxgBio
via IFTTT

Aucun commentaire:

Enregistrer un commentaire