Configuring nginx

March 27, 2013 10.2k views
Can I copy and paste the info into this file as it or change the values individually. Can someone take me through exactly what I do here: Add index.php to the index line. Change the server_name from local host to your domain name or IP address (replace the in the configuration) Change the correct lines in “location ~ \.php$ {“ section
3 Answers
It depends on what you have processing your PHP code in our case we have a writeup on getting a LEMP stack up and running using php5-fpm to process PHP.

You can find the full writeup here:

The nginx config file would be setup as follows in that case:

server {
listen 80;

root /usr/share/nginx/www;
index index.php index.html index.htm;


location / {
try_files $uri $uri/ /index.html;

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;

# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;


by Etel Sverdlov
LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. This tutorial explains how to install the required repos to download nginx and php-fpm, how to install MySQL, how to install nginx, how to install php-fpm, how to configure php and nginx, and how to create a php info page. This tutorial is written for Ubuntu 12.04.
I got this message when I restarted nginx: configuration file /etc/nginx/nginx.conf test failed
This was the message:Restarting nginx: nginx: [emerg] unexpected end of file, expecting "}" in /etc/n ginx/sites-enabled/default:121
Have another answer? Share your knowledge.