From 5e517adf684865c15e434ec9291dada7ec1152e4 Mon Sep 17 00:00:00 2001 From: indolering Date: Wed, 23 Oct 2013 13:01:22 -0700 Subject: [PATCH 1/2] Refactor * Added conditional mod_headers to the one liner CORS entry. * Pushed the simplist/easiest options at the top. * Moved more advanced configurations options to the bottom. Added troubleshooting advice. --- server_apache.html | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/server_apache.html b/server_apache.html index 65b8961..f5df775 100644 --- a/server_apache.html +++ b/server_apache.html @@ -6,19 +6,32 @@

CORS on Apache

+

The easiest way to CORS authorization on an Apache webserver is to include the following lines in an .htaccess file at the website's root directory:

+ +
+<IfModule mod_headers.c>
+  Header set Access-Control-Allow-Origin "*"
+</IfModule>
-

- Apache can be configured to expose this header using mod_headers, this is enabled by default in Apache however you may want to ensure it's enabled by running the following command: -

-
a2enmod headers
-

- To expose the header, you simply add the following line inside either the <Directory>, <Location>, <Files> or <VirtualHost> sections of your server config (usually located in a *.conf file, such as httpd.conf or apache.conf), or within a .htaccess file: -

-
Header set Access-Control-Allow-Origin "*"
-

- Note: you can also use add rather than set, but be aware that add can add the header multiple times, so it's likely safer to use set. Eventually, you may need to reload Apache to make sure your changes are applied. -

+ If no .htaccess file exists, simply create a new one. If an .htaccess file already exists, make a backup of it and then add the above lines. Finally, reload Apache to make sure your changes are applied:

+
sudo service apache2 reload
+ or
apachectl -k graceful
+ +

You can also add the above lines to <Directory>, <Location>, <Files> or <VirtualHost> sections of your server config. Also note that you can also use add rather than set, but be aware that add can add the header multiple times, so it's likely safer to use set.

+ +

Troubleshooting

+ +

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

+ +
apachectl configtest
+ +

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

+ +

Altering headers requires the use of mod_headers. Mod_headers is enabled by default in Apache, however, you may want to ensure it's enabled by running a2enmod headers on the command line.

+

+If you are still having trouble and Google isn't providing any answers, you can always post a question to the Pro Webmasters site. Remember to use the CORS and Apache tags. +

From 4ed980cdc0c85baec8e16eb05a7ea89df58841aa Mon Sep 17 00:00:00 2001 From: indolering Date: Wed, 23 Oct 2013 13:28:42 -0700 Subject: [PATCH 2/2] Moved server pages under /server/ directory * Removed 'server_" from names of server pages. * /server.html->/server/index.html * Changed Q/A link on Apache config page to ServerFault * Minor text changes to index --- _layouts/default.html | 2 +- index.html | 2 +- server_apache.html => server/apache.html | 4 +-- .../appengine.html | 0 server_aspnet.html => server/aspnet.html | 0 server_cgi.html => server/cgi.html | 2 +- .../expressjs.html | 0 server_iis6.html => server/iis6.html | 0 server_iis7.html => server/iis7.html | 0 server.html => server/index.html | 27 +++++++++---------- server_nginx.html => server/nginx.html | 0 server_perl.html => server/perl.html | 2 +- server_php.html => server/php.html | 0 server_virtuoso.html => server/virtuoso.html | 0 server_wcf.html => server/wcf.html | 0 15 files changed, 19 insertions(+), 20 deletions(-) rename server_apache.html => server/apache.html (91%) rename server_appengine.html => server/appengine.html (100%) rename server_aspnet.html => server/aspnet.html (100%) rename server_cgi.html => server/cgi.html (92%) rename server_expressjs.html => server/expressjs.html (100%) rename server_iis6.html => server/iis6.html (100%) rename server_iis7.html => server/iis7.html (100%) rename server.html => server/index.html (58%) rename server_nginx.html => server/nginx.html (100%) rename server_perl.html => server/perl.html (87%) rename server_php.html => server/php.html (100%) rename server_virtuoso.html => server/virtuoso.html (100%) rename server_wcf.html => server/wcf.html (100%) diff --git a/_layouts/default.html b/_layouts/default.html index 3476b25..56a7190 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -53,7 +53,7 @@

Who’s behind this

Contribute

-

The content on this site stays fresh thanks to help from users like you! If you have suggestions or would like to contribute, fork us on GitHub.

+

If you have suggestions or would like to contribute, fork us on GitHub!

diff --git a/index.html b/index.html index 2e58f7c..2e1c965 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,7 @@

Why is CORS important?

diff --git a/server_apache.html b/server/apache.html similarity index 91% rename from server_apache.html rename to server/apache.html index f5df775..b914dae 100644 --- a/server_apache.html +++ b/server/apache.html @@ -13,7 +13,7 @@

CORS on Apache

Header set Access-Control-Allow-Origin "*" </IfModule> - If no .htaccess file exists, simply create a new one. If an .htaccess file already exists, make a backup of it and then add the above lines. Finally, reload Apache to make sure your changes are applied:

+ If no .htaccess file exists, simply create a new one. If an .htaccess file already exists, make a backup of it and then add the above lines. Finally, reload Apache to make sure your changes are applied:

sudo service apache2 reload
or
apachectl -k graceful
@@ -30,7 +30,7 @@

Troubleshooting

Altering headers requires the use of mod_headers. Mod_headers is enabled by default in Apache, however, you may want to ensure it's enabled by running a2enmod headers on the command line.

-If you are still having trouble and Google isn't providing any answers, you can always post a question to the Pro Webmasters site. Remember to use the CORS and Apache tags. +If you are still having trouble and Google isn't providing any answers, you can always post a question to the Q/A site ServerFault.

diff --git a/server_appengine.html b/server/appengine.html similarity index 100% rename from server_appengine.html rename to server/appengine.html diff --git a/server_aspnet.html b/server/aspnet.html similarity index 100% rename from server_aspnet.html rename to server/aspnet.html diff --git a/server_cgi.html b/server/cgi.html similarity index 92% rename from server_cgi.html rename to server/cgi.html index 0eae167..b4e151a 100644 --- a/server_cgi.html +++ b/server/cgi.html @@ -19,7 +19,7 @@

CORS in CGI Scripts

-content_location => 'mydata.ttl', -access_control_allow_origin => '*', ); -

For a more modern way of enabling CORS in Perl server scripts, see the Perl page.

+

For a more modern way of enabling CORS in Perl server scripts, see the Perl page.

or in Python:

diff --git a/server_expressjs.html b/server/expressjs.html similarity index 100% rename from server_expressjs.html rename to server/expressjs.html diff --git a/server_iis6.html b/server/iis6.html similarity index 100% rename from server_iis6.html rename to server/iis6.html diff --git a/server_iis7.html b/server/iis7.html similarity index 100% rename from server_iis7.html rename to server/iis7.html diff --git a/server.html b/server/index.html similarity index 58% rename from server.html rename to server/index.html index 307abf0..955e6ad 100644 --- a/server.html +++ b/server/index.html @@ -11,24 +11,23 @@

I want to add CORS support to my server

Access-Control-Allow-Origin: *

-

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 Using CORS tutorial on HTML5 Rocks.

- +

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 Using CORS tutorial on HTML5 Rocks.

If you want the TL;DR version, take a look at the flowchart for implementing CORS support.

If you'd like to learn more about implementing CORS for a specific platform, follow one of the links below:

diff --git a/server_nginx.html b/server/nginx.html similarity index 100% rename from server_nginx.html rename to server/nginx.html diff --git a/server_perl.html b/server/perl.html similarity index 87% rename from server_perl.html rename to server/perl.html index 3204060..573b1a2 100644 --- a/server_perl.html +++ b/server/perl.html @@ -19,7 +19,7 @@

CORS in Perl PSGI scripts

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

-

For other Perl-related uses see the CGI page.

+

For other Perl-related uses see the CGI page.

diff --git a/server_php.html b/server/php.html similarity index 100% rename from server_php.html rename to server/php.html diff --git a/server_virtuoso.html b/server/virtuoso.html similarity index 100% rename from server_virtuoso.html rename to server/virtuoso.html diff --git a/server_wcf.html b/server/wcf.html similarity index 100% rename from server_wcf.html rename to server/wcf.html