Thursday, 31 January 2013

Setting up a Django-Nginx web server on Raspberry Pi

Today I installed the Django web framework on my Raspberry Pi, using Nginx as the web server and fastcgi to delegate page requests to Django. Here is a summary of the steps involved, for future reference. I hope it's effective so please comment if anything is unclear.

1. Install Django and Nginx

I used Paul Hallett's one-click installer. When it finishes it reports the Django version (such as 1.4.1) if successful. Note that his script installs a local version of Python so bear in mind some packages may need to be symlinked to work.

2. Configure Nginx

There's a useful and informative article on using Nginx for personal websites on Ars Technica. Ignore the part to install the development version because there isn't a pre-built package for the ARM11 CPU used in the Raspberry Pi. Once installed (I'm using nginx version 1.2.1 from the Raspbian repository), you need to edit the file: /etc/nginx/nginx.conf

worker_processes 1;
The Raspberry Pi has only a single CPU core so there's no need for more than one worker process. This file can also be tweaked for compressing large files, and to improve security (not covered here).

Create a new website corresponding to a URL such as www.mysite.org by copying the default file. Name it according to your URL.

cd /etc/nginx/sites-available/
cp default www
ln -s /etc/nginx/sites-available/www /etc/nginx/sites-enabled/www
rm /etc/nginx/sites-enabled/default
The last 2 commands enable your new site and disable the default one. Edit the new file as follows:
server {
 listen   80;
 #listen   [::]:80 default_server ipv6only=on;

 root /var/html/www;
 index index.html index.htm;
 access_log /var/log/nginx/www.access.log;
 error_log /var/log/nginx/www.error.log;

 # Make site accessible from http://localhost/
 server_name localhost;

 location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  # try_files $uri $uri/ /index.html;
  # Uncomment to enable naxsi on this location
  # include /etc/nginx/naxsi.rules

  # Django
  # https://code.djangoproject.com/wiki/DjangoAndNginx
  include fastcgi_params;
  fastcgi_pass 127.0.0.1:8080;
 }
}

The root tag is where your website files would normally be installed. However, your Django site can be placed anywhere. The access_log and error_log tags are useful for logging information. The important tags are include fastcgi_params and fastcgi_pass 127.0.0.1:8080 which tells nginx to forward page requests to Django on port 8080. See the Django and Nginx Wiki for further info. Restart nginx to load your new settings.

sudo /etc/init.d/nginx reload

3. Set up Django and fastcgi

Install Flup and ensure it's in your Python path (check your local configuration). Version 0.5 or later should be ok, I have 1.0 from the Raspbian repo.

sudo aptitude install python-flup
sudo ln -s /usr/lib/python2.7/dist-packages/flup* \
  ~/lib/python2.7/site-packages/

4. Create a test website

Following the Django tutorial, create your test site as follows.

django-admin.py startproject mysite
cd mysite
python ./manage.py runfcgi host=127.0.0.1 port=8080
Your website is now running and if all goes well Nginx will forward requests to port 8080. Type in the IP address of your Raspberry Pi into a browser window on another machine, and you should see a welcome to Django message. That means it worked! :)

Links

Wednesday, 16 November 2011

Extrasolar planets -- 1 year later


Last October (2010) I wrote a post on extrasolar planets. At that time almost 500 planets beyond our Solar System had been discovered. In the past year, 200 new planets have been confirmed, so I decided it's time to update the chart!

There are a number of recent discoveries around 10 Earth masses (0.03 Jupiter masses) and an over abundance of planets at 0.05 AU (7 million kilometres) from their parent Sun, the well-known 'hot Jupiters'. There is another class of cooler giant planets around 1-5 AU. Several 'super Earths' discovered by micro-lensing can also be seen on the chart.

Will there be 1000 known planets when I update the chart in autumn 2012? Let's see!

Wednesday, 3 August 2011

Pluto's 4th moon

Recent Hubble images have revealed a new moon orbiting Pluto, the fourth so far discovered around the icy dwarf planet. P4 as the moon is currently known, is the smallest so far discovered at 15 to 30km across, and lies between Nix and Hydra, two small moons discovered in 2005.






MoonMean distance (km)Period (d)Year of discovery
Charon17,5406.3871978
Nix48,71024.8562005
S/2011 P1~59,00032.12011
Hydra64,75038.2062005



The moon was unexpectedly found during an observing campaign to find rings around Pluto, which remain undiscovered. The new moon was first seen in an image taken on the 28th June and will be further studied during NASA's New Horizons mission, scheduled to fly through the Pluto system in 2015.

Links


Tuesday, 10 May 2011

A foray into Spectroscopy

In January I acquired a `Star Analyser 100 spectroscope', a diffraction grating which screws into a 1.25-inch eyepiece just like a colour filter. Well, here are my first results captured with an Imaging Source DFK21 camera and processed with Valerie Desnoux's Visual Spec software which is excellent (and free!).

Betelgeuse spectrum

I used Sirius (spectral type A0V) to calibrate the image which has a resolution of 10.5 Angstroms per pixel. The final spectrum (green) is shown between 4000 and 7000 Angstroms (note my response curve has sadly missed the Halpha line at 6563 Angstroms) based on 17 seconds of raw video. The black curve shows a reference red supergiant spectrum of class M2.

Also shown for interest are the Balmer series of H lines (red) and Ti lines (blue).

Links


Friday, 18 February 2011

AstroFest 2011

For 2 days each year at the start of February, the UK astronomy magazine "Astronomy Now" organises a national festival celebrating recent news in astronomy and bringing amateurs together to hone their skills. This year I was lucky to visit the conference on both Friday and Saturday and there were some excellent talks on Phobos and Deimos (Emily Baldwin), epsilon Aurigae (Nathalie Thureau), Uranus & Neptune (Chris Arridge) and the Moon (Chuck Wood) amongst several others. Sadly I missed the principal galactic astronomy talk by Gerry Gilmore of Cambridge University because session 4 (Saturday afternoon) was already sold out.


I also enjoyed the trade stalls in particular those of the BAA and Ian King Imaging/Shelyak Instruments, the latter a French company specialising in spectroscopes for amateur astronomers. I would love to buy their LISA instrument but the Star Analyser is more realistic for my budget/telescope!



Ian Ridpath during the Friday afternoon session interval




Nathalie Thureau describes the CHARA infra-red interferometer




"It's not Rocket Science", a very amusing space-themed comedy show by Helen Keen (Radio 4 in March/April)




Links


Saturday, 30 October 2010

Saturn and family from Cassini

A selection of images which featured in the wonderful talk by Professor Carl Murray (Queen Mary University, London) at the SPA Autumn 2010 meeting. Prof Murray's research interests are in solar system dynamics and currently the dynamics of Saturn's mysterious F-ring. Since 1990 he is working on the Imaging Science Subsystem on the Cassini spacecraft which is currently orbiting Saturn.

PIA 08329: Backlit Saturn and Earth




Looking back towards the inner solar system from Saturn (a distance of 1400 million kilometres), this image shows Saturn's disc and rings backlit by the Sun. It is a sobering thought that the tiny pale blue dot visible in this colour-enhanced image, is our planet Earth! (Look inside the G ring and above the brighter main rings to the left of Saturn.)



PIA 13424: The colourful equator of Rhea




These colour-enhanced images show recent bluish material which was presumably deposited on Rhea's surface since the formation of the impact craters. The image size is 130km across, about the size of the home counties of South-East England.



PIA 11688: Bursting at the Seams




A superb view of the plumes near the south pole of Enceladus, taken when Cassini flew through the jets on November 21st, 2009. The jets emerge from the tiger stripes which may contain liquid water, despite Enceladus receiving only 1 per-cent of the sunlight that Earth receives.



PIA 12481: Reflection of sunlight off Titan lake




As the Sun sets on Titan, sunlight glints off a hydrocarbon lake in this infra-red image taken on July 8th, 2009.



PIA 11690: Global view of Iapetus dichotomy




About 40 per-cent of the surface of Iapetus is coated in a dark material, deposited on the leading hemisphere. This material is thought to originate on Phoebe and causes the icy surface to melt further due to decreased reflectivity, relative to the uncoated trailing hemisphere. Over a long timescale this reinforces the contrast to its present-day level. The irregularly-shaped moon Hyperion is also coated but its chaotic rotation means the coating is uniform.

Thursday, 28 October 2010

Shapiro delay weighs super-heavy neutron star

Radio astronomers in the U.S. and the Netherlands have announced the accurate weighing of a neutron star-white dwarf binary, revealing the neutron star to be almost 50 per-cent heavier than most other neutron stars. Their results appeared yesterday in the scientific journal Nature.

Neutron stars are found in a variety of binary stars, which provides a means to determine their masses using Kepler's Laws -- possibly modified to tske into account relativity.

A much more accurate technique using the Shapiro Delay (named after Harvard Professor Irwin Shapiro) is possible for the double neutron stars in which one star is a radio pulsar. If the path of the radio pulse passes close to the companion star it will be delayed by a tiny amount, which is measurable with very accurate clocks on Earth. The technique can also be applied to white dwarf-pulsar systems with reduced accuracy due to the weaker gravitational field of a white dwarf star.

As an example, the famous binary known as PSR B1913+16 is made up of neutron stars with 1.441 and 1.387 times the mass of our Sun. Surprisingly, these kinds of stars often turn out to have masses very close to 1.4 times the Sun's mass. The new observation of 1.97+/-0.04 times the Sun's mass for J1614-2230 is all the more remarkable, and provides new clues to physicists studying the interiors of neutron stars.

Double neutron star systems are also unique laboratories for testing General Relativity. The first one to be discovered, PSR1913+16 won Russell Hulse and Joseph Taylor the 1993 Nobel Prize in Physics. In 2004 an international team including scientists at Manchester University in the UK discovered an even rarer double pulsar.

Links


Astronomy Now article by Keith Cooper.
Ars Technica news story.