The last 1 or 2 years I have been running nginx as reverse proxy in front of Apache2. Now with the release of nginx version 1.2.0 I decided to revamp my installation and use nginx as a standalone server again. This guide explains my installation which uses nginx, PHP via FastCGI connector and SSL running on Ubuntu 10.04.
I want to use the current version of nginx, so I use the PPA repository where current nginx builds can be found:
Currently this will install nginx version 1.2.0. Now install the packages required for php:
Now we need to create a start/stop script to start our cgi process. Create a file /etc/init.d/php-fastcgi
with the following contents:
This script will start 3 PHP worker processes which will server up to 1000 requests each. Make the script executable:
Now you can try to start the php daemon:
You should see the daemons in the process list. If everything is running so far, enable autostart for the service:
The next step is to create a self signed SSL certificate:
When filling out the certificate details, make sure that you enter your domain name in the field “Common Name”. The above command will create a self signed certificate file.
The last step is to create virtual host configurations for nginx. Here is an example which can act as a boilerplate to setting up a new vhost which will listen on http and https. Let’s say we want to create a vhost for a domain mydomain.com
where the files are located at /srv/www/vhosts/mydomain.com/httpdocs
. Create a new file /etc/nginx/sites-available/mydomain.com
with the following contents:
If you want to redirect all non-ssl traffic to the https port, add the following lines inside the server block:
To activate the vhost, create a symbolic link in the directory /etc/nginx/sites-enabled/
:
And now reload the nginx configuration:
Everything should be working by now.
Leave a Reply