Skip to content
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

Refactor Apache instructions #61

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2>Who’s behind this</h2>

<div class="span5">
<h2>Contribute</h2>
<p>The content on this site stays fresh thanks to help from users like you! If you have suggestions or would like to contribute, <a href="https://github.com/mhausenblas/enable-cors.org">fork us on GitHub</a>.</p>
<p>If you have suggestions or would like to contribute, <a href="https://github.com/mhausenblas/enable-cors.org">fork us on GitHub</a>!</p>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Why is CORS important?</h2>

<div class="row-fluid" style="text-align: center;">
<div class="span4">
<a href="server.html">
<a href="server/index.html">
<img src="img/cloud-download.svg" alt="CORS on the server" width="128" height="128" />
<h3>CORS on the server</h3></a>
</div>
Expand Down
37 changes: 37 additions & 0 deletions server/apache.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
layout: default
title: enable cross-origin resource sharing
---

<div class="container">
<section>
<h1>CORS on Apache</h1>
<p>The easiest way to CORS authorization on an Apache webserver is to include the following lines in an <code>.htaccess</code> file at the website's root directory:</p>

<pre class="code">
&lt;IfModule mod_headers.c&gt;
Header set Access-Control-Allow-Origin "*"
&lt;/IfModule&gt;</pre>

If no <code>.htaccess</code> file exists, simply create a new one. If an <code>.htaccess</code> file already exists, make a backup of it and then add the above lines. Finally, <a href="https://httpd.apache.org/docs/2.2/stopping.html">reload Apache</a> to make sure your changes are applied:<p></p>
<pre>sudo service apache2 reload</pre>
or <pre>apachectl -k graceful</pre>

<p> You can also add the above lines to <code>&lt;Directory&gt;</code>, <code>&lt;Location&gt;</code>, <code>&lt;Files&gt;</code> or <code>&lt;VirtualHost&gt;</code> sections of your <a href="https://wiki.apache.org/httpd/DistrosDefaultLayout">server config</a>. Also note that you can also use <code>add</code> rather than <code>set</code>, but be aware that <code>add</code> can add the header multiple times, so it's likely safer to use set.</p>

<h2>Troubleshooting</h2>

<p>It is strongly reccomended that you backup your original file and test your new config before applying:</p>

<pre class="code">apachectl configtest</pre>

<p> If you run into errors, restore your backup configuration files and run <code>apachectl configtest</code> again. If your config files run without error, ensure that you have copied everything exactly and that the <code>Header set Access-Control-Allow-Origin "*"</code> line is in the correct place.</p>

<p class="note">Altering headers requires the use of <a href="http://httpd.apache.org/docs/2.0/mod/mod_headers.html">mod_headers</a>. Mod_headers is enabled by default in Apache, however, you may want to ensure it's enabled by running <code>a2enmod headers</code> on the command line.</p>

<p>
If you are still having trouble and Google isn't providing any answers, you can always post a question to the Q/A site <a href="http://serverfault.com/search?q=cors">ServerFault</a>.
</p>
</section>
</div>

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion server_cgi.html → server/cgi.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1>CORS in CGI Scripts</h1>
-content_location => 'mydata.ttl',
-access_control_allow_origin => '*',
);</pre>
<p>For a more modern way of enabling CORS in Perl server scripts, see <a href="server_perl.html">the Perl page</a>.</p>
<p>For a more modern way of enabling CORS in Perl server scripts, see <a href="perl.html">the Perl page</a>.</p>
<p>
or in Python:
</p>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 13 additions & 14 deletions server.html → server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ <h1 id="server-side">I want to add CORS support to my server</h1>

<p><code>Access-Control-Allow-Origin: *</code></p>

<p>There are some more headers and settings involved if you want to support verbs other than GET/POST, custom headers, or authentication. You can learn more about these options in the <a href="http://www.html5rocks.com/en/tutorials/cors/">Using CORS</a> tutorial on HTML5 Rocks.<p>

<p>There are some more headers and settings involved if you want to support verbs other than GET/POST, custom headers, or authentication. You can learn more about these options in the <a href="http://www.html5rocks.com/en/tutorials/cors/">Using CORS</a> tutorial on HTML5 Rocks.
<p>If you want the TL;DR version, take a look at the <a href="http://www.html5rocks.com/static/images/cors_server_flowchart.png">flowchart for implementing CORS support</a>.</p>

<p>If you'd like to learn more about implementing CORS for a specific platform, follow one of the links below:</p>
<ul>
<li><a href="server_apache.html">Apache</a></li>
<li><a href="server_appengine.html">App Engine</a></li>
<li><a href="server_aspnet.html">ASP.NET</a></li>
<li><a href="server_cgi.html">CGI Scripts</a></li>
<li><a href="server_expressjs.html">ExpressJS</a></li>
<li><a href="server_iis6.html">IIS6</a></li>
<li><a href="server_iis7.html">IIS7</a></li>
<li><a href="server_nginx.html">nginx</a></li>
<li><a href="server_perl.html">Perl</a></li>
<li><a href="server_php.html">PHP</a></li>
<li><a href="server_virtuoso.html">Virtuoso</a></li>
<li><a href="server_wcf.html">WCF</a></li>
<li><a href="apache.html">Apache</a></li>
<li><a href="appengine.html">App Engine</a></li>
<li><a href="aspnet.html">ASP.NET</a></li>
<li><a href="cgi.html">CGI Scripts</a></li>
<li><a href="expressjs.html">ExpressJS</a></li>
<li><a href="iis6.html">IIS6</a></li>
<li><a href="iis7.html">IIS7</a></li>
<li><a href="nginx.html">nginx</a></li>
<li><a href="perl.html">Perl</a></li>
<li><a href="php.html">PHP</a></li>
<li><a href="../server_virtuoso.html">Virtuoso</a></li>
<li><a href="wcf.html">WCF</a></li>
</ul>
</section>
</div>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion server_perl.html → server/perl.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1>CORS in Perl PSGI scripts</h1>

<p>This module is also available in Debian and Ubuntu as libplack-middleware-crossorigin-perl.</p>

<p>For other Perl-related uses see <a href="server_cgi.html">the CGI page</a>.</p>
<p>For other Perl-related uses see <a href="cgi.html">the CGI page</a>.</p>
</section>
</div>

File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions server_apache.html

This file was deleted.