Note that there are some explanatory texts on larger screens.

plurals
  1. PONginx/phpfpm CORS request not going through
    text
    copied!<p>I have been searching around for CORS request conf in nginx and arrived at this configuration:</p> <pre><code>server { listen 80; server_name apibackend; root /mnt/www/apibackend/public; access_log /var/log/nginx/apibackend.access.log; error_log /var/log/nginx/apibackend.error.log; # serve static files directly location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location /{ index index.html index.htm index.php; #try static .html file first try_files $uri $uri/ /index.php?q=$uri&amp;$args; } # catch all error_page 404 /index.php; location ~ \.php$ { add_header 'Access-Control-Allow-Origin' "*"; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Access-Control-Allow-Methods' 'GET, POST, UPDATE, DELETE, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since'; add_header 'Content-Length' 0; add_header 'Content-Type' 'text/plain charset=UTF-8'; include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; 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; } </code></pre> <p>}</p> <p>When I access it directly from my browser, everything is fine, the headers I added are here:</p> <pre><code>HTTP/1.1 200 OK Server: nginx/1.4.0 Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/5.3.10-1ubuntu3.6 Set-Cookie: laravel_session=7o4v2fiu460q9p9h2hfo9lpnv6; expires=Mon, 27-May-2013 17:03:02 GMT; path=/ Cache-Control: no-cache Date: Mon, 27 May 2013 15:03:02 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Max-Age: 1728000 Access-Control-Allow-Methods: GET, POST, UPDATE, DELETE, OPTIONS Access-Control-Allow-Headers: Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since Content-Length: 0 Content-Type: text/plain charset=UTF-8 Access-Control-Allow-Headers: Authorization Content-Encoding: gzip </code></pre> <p>But, when I access it from my app, which is on another domain (angularJS app), the headers don't appear!</p> <pre><code>Connection:keep-alive Content-Type:text/html Date:Mon, 27 May 2013 15:03:12 GMT Server:nginx/1.4.0 Set-Cookie:laravel_session=k9bastale5kuo0afndbp261025; expires=Mon, 27-May-2013 17:03:12 GMT; path=/; HttpOnly Transfer-Encoding:chunked X-Powered-By:PHP/5.3.10-1ubuntu3.6 </code></pre> <p>And then, I have an error :</p> <pre><code>OPTIONS apibackend 500 (Internal Server Error) angular.min.js:99 OPTIONS apibackend Origin angularapp is not allowed by Access-Control-Allow-Origin. angular.min.js:99 XMLHttpRequest cannot load apibackend. Origin angularapp is not allowed by Access-Control-Allow-Origin. </code></pre> <p>I have been trying all around, but no clue left.</p> <p>Thanks for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload