Skip to content

Instantly share code, notes, and snippets.

@hjr3
Created September 23, 2012 17:58
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save hjr3/3772519 to your computer and use it in GitHub Desktop.
Save hjr3/3772519 to your computer and use it in GitHub Desktop.
nginx phpfpm + CORS configuration
upstream phpfpm {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name _;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ "\.php$" {
# requires http://wiki.nginx.org/HttpHeadersMoreModule to handle response codes that add_header ignores
more_set_headers "Access-Control-Allow-Origin: $http_origin";
more_set_headers "Access-Control-Allow-Credentials: true";
more_set_headers "Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS";
more_set_headers "Access-Control-Allow-Headers: Keep-Alive,User-Agent,If-Modified-Since,Cache-Control,Content-Type,Authorization";
more_set_headers "Access-Control-Max-Age: 1728000";
include fastcgi_params;
fastcgi_pass phpfpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
@Ahmedsaber9
Copy link

Thanks.

@sterichards
Copy link

nginx: [emerg] unknown directive "more_set_headers" in /etc/nginx/conf.d/default.conf:9

@hjr3
Copy link
Author

hjr3 commented Mar 16, 2023

nginx: [emerg] unknown directive "more_set_headers" in /etc/nginx/conf.d/default.conf:9

https://gist.github.com/hjr3/3772519#file-nginx-conf-L16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment