Skip to content

Instantly share code, notes, and snippets.

@syntaxlexx
Forked from hjr3/nginx.conf
Last active January 20, 2019 13:06
Show Gist options
  • Save syntaxlexx/35065ad373bd93830c9e4b1fcf781ac0 to your computer and use it in GitHub Desktop.
Save syntaxlexx/35065ad373bd93830c9e4b1fcf781ac0 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,X-Requested-With,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