E
E
enchikiben2015-12-11 11:06:33
Nginx
enchikiben, 2015-12-11 11:06:33

Setting up nginx, why is the request not being passed to php-fpm?

Good afternoon!
There is this config:

server {
        charset utf-8;
        client_max_body_size 128M;

        listen 80; ## listen for ipv4

        server_name tes.lc;
        root        /path/web;
        index       index.php;

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

        location ~* \.php$ {
                fastcgi_index   index.php;
                fastcgi_pass   unix:/var/run/php5-fpm.sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
}

and if you open the site, then it all works, but if you send a cross-domain request, then first a "preflight" OPTIONS request is sent and for some reason it does not come to php. Tell me how to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2015-12-11
@Nc_Soft

As for me, it's better to handle options by nginx itself, so as not to pull PHP once again
Instead of add_header 'Access-Control-Allow-Origin' "$http_origin"; in production, you need to hardcode the domain

if ($request_method = 'OPTIONS') {
      add_header 'Access-Control-Allow-Origin' "$http_origin";
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Origin,Accept';
      add_header 'Content-Type' 'application/json';
      add_header 'Content-Length' 0;
 
      return 204;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question