Raspberry Pi: nginx Webserver with PHP and SSL

Installing the needed packages:

pi@raspberrypi ~ $ sudo aptitude install nginx php5-fpm php5-cgi php5-cli php5-common

There are different version of nginx available. For a comparison take a look at the debian wiki: https://wiki.debian.org/Nginx

Create the needed directory and php test file for later:

pi@raspberrypi ~ $ sudo mkdir /var/www
pi@raspberrypi ~ $ echo „<?php phpinfo(); ?>“ | sudo  tee /var/www/index.php
pi@raspberrypi ~ $ sudo chown -R www-data:www-data /var/www

Setting up SSL:

pi@raspberrypi ~ $ sudo mkdir /etc/nginx/conf.d/ssl && cd /etc/nginx/conf.d/ssl
pi@raspberrypi /etc/nginx/conf.d/ssl $ sudo openssl genrsa -out server.key 2048
pi@raspberrypi /etc/nginx/conf.d/ssl $ sudo openssl req -new -key server.key -out server.csr
pi@raspberrypi /etc/nginx/conf.d/ssl $ sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

And finally configure nginx:

pi@raspberrypi /etc/nginx/conf.d/ssl $ sudo vi /etc/nginx/sites-available/default

server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
try_files $uri $uri/ /index.html;
}
}

# HTTPS server
#
server {
listen 443;
server_name localhost;
root /var/www;
autoindex on;
index index.php index.html index.htm;
ssl on;
ssl_certificate /etc/nginx/conf.d/ssl/server.crt;
ssl_certificate_key /etc/nginx/conf.d/ssl/server.key;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
try_files $uri $uri/ /index.html;
}
}

Visit http://localhost or https://localhost and you should see your php configuration.