Skip to content

Fixed nginx configuration. #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions server_nginx.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<h1>CORS on Nginx</h1>

<p>The following Nginx configuration enables CORS, with support
for preflight requests.</p>
for preflight requests on all successful responses.</p>

<pre class="code">
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Origin' '$http_origin';
#
# Om nom nom cookies
#
Expand Down Expand Up @@ -50,4 +50,26 @@ <h1>CORS on Nginx</h1>
</pre>
Source: Michiel Kalkman, <a href="https://michielkalkman.com/snippets/nginx-cors-open-configuration.html">https://michielkalkman.com/snippets/nginx-cors-open-configuration.html</a>
</section>

<p>The following Nginx configuration enables CORS for all request statuses including 4xx and 5xx errors.
This configuration requires the use of <a href="http://wiki.nginx.org/HttpHeadersMoreModule">HttpHeadersMoreModule</a>
which usually requires extra steps to install.</p>

<pre class="code">
location / {
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, PUT, DELETE, PATCH, HEAD, OPTIONS';
more_set_headers 'Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

if ($request_method = 'OPTIONS') {
# Tell client that this pre-flight info is valid for 20 days
#
more_set_headers 'Access-Control-Max-Age: 1728000';
more_set_headers 'Content-Type: text/plain charset=UTF-8';
more_set_headers 'Content-Length: 0';
return 204;
}
}
</pre>
</div>