Skip to content

Instantly share code, notes, and snippets.

@chusri
Forked from hjr3/nginx.conf
Created March 17, 2017 16:22
Show Gist options
  • Save chusri/7094fc64277749f336eca3f2a46cfce9 to your computer and use it in GitHub Desktop.
Save chusri/7094fc64277749f336eca3f2a46cfce9 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment