D
D
Dima Pautov2018-08-19 14:02:14
Nginx
Dima Pautov, 2018-08-19 14:02:14

How to properly set up cors headers?

Good afternoon guys. Help me to understand. I don’t really know how much I’ve been googling, but I just can’t figure it out.
I have a vps with nuxt.js application and yii2 backend. I don’t understand fundamentally how to set up cors.
api : ' 178.62.226.252/api '
http - axios Deploying a nuxt
dev server on localhost ( http://localhost:3000), what should I write in the nginx config so that I can send requests to the server from localhost normally and pass headers to the server ?
I have this rule in nginx for api:

location ~* /api(.*) {
        auth_basic "off";
        root $php_root_path;
        try_files $uri $uri/ /index.php?$args;
    }

I tried to do it like here , the server generally died after restarting the config.
At the moment, get requests are working as they should, but for example, the post request does not work, it gives me this message in the browser:
Failed to load http://178.62.226.252/api/user/sign-up: Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

network tab
5b794d9b19ff3533129677.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-08-19
@Arik

Why nginx? Or are you also closing the static? so yii has https://www.yiiframework.com/doc/api/2.0/yii-filte... and put what you need there. You can dig for nginx configs https://github.com/h5bp/server-configs-nginx there are a lot of interesting things

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question