Hey guys,
This is my first tutorial. I was just browsing ‘Tutorials and Guides’ section and noticed few Nginx related tutorials. But none of them were complete tutorials. I mean installing Nginx is just a piece of big pie. You need to prepare your Linux for it. And after installation, what should you do? Can you install a WordPress or PHP base applications? Well, you can try your luck.
So I don’t have time to write all this. I have it covered on my blog ‘Step-by-Step Guide to WordPress on Nginx Server’. What I’m going to do here is, tell you the proper way of installing latest version of Nginx on an Ubuntu VPS. All additional details and background can be found at above mentioned post. And remember this is just a one part of many.
I need latest version of Nignx. So I won’t mess with integrated packages. I’ll install it from source. So we need to collect some dependency files. Below code will do it,
We need a folder inside our Ubuntu box to download installation files. Let’s create it,
We’ll use ‘wget’ to download latest release or Nginx from official site. As for today, latest version is 1.2.0. To make sure you get the latest version, go to this page and find out if it’s still the up to date version. Change the version number accordingly on below code if it’s deferent from official site. Following code will download it.
Extract it,
Navigate to extracted folder,
Now configure it. Note that code at the end. ‘--with-http_ssl_module’ it’s for SSL support. You probably don’t need it unless you have a SSL license. Just remove it.
Below command will install Nginx on your Ubuntu box.
Now fire it up,
That’s it. Open your ip in browser and it should say ‘Welcome to nginx!’
That’s it right? No not exactly.
Nginx won’t auto start on reboots. So let’s make it happen.
First kill Nginx,
We’ll create a script to do it. So create a new file,
Paste this lot to new file,
Give permissions to it,
Let’s tell Nginx how it should be working on our box. Open Nginx configuration file,
Delete everything on that file and paste following,
Save and close.
Let’s create Virtual Host File Structure & Symlinks,
We need 2 new folders
Create default default vhost file,
And paste default rules into it,
Enable vhost
Restart Nginx
Check your ip again. It should still say ‘Welcome to Nginx!’
That’s it! Nginx is now working properly. Remember this is 5th post of my Nginx series. All other tutorials are available at my blog.
Source - Install and Configure Nginx Web Server on Ubuntu VPS
This is my first tutorial. I was just browsing ‘Tutorials and Guides’ section and noticed few Nginx related tutorials. But none of them were complete tutorials. I mean installing Nginx is just a piece of big pie. You need to prepare your Linux for it. And after installation, what should you do? Can you install a WordPress or PHP base applications? Well, you can try your luck.
So I don’t have time to write all this. I have it covered on my blog ‘Step-by-Step Guide to WordPress on Nginx Server’. What I’m going to do here is, tell you the proper way of installing latest version of Nginx on an Ubuntu VPS. All additional details and background can be found at above mentioned post. And remember this is just a one part of many.
I need latest version of Nignx. So I won’t mess with integrated packages. I’ll install it from source. So we need to collect some dependency files. Below code will do it,
Code:
sudo aptitude -y install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
Code:
mkdir ~/sources
cd ~/sources/
Code:
wget http://nginx.org/download/nginx-1.2.0.tar.gz
Code:
tar -zxvf nginx-1.0.12.tar.gz
Code:
cd nginx-1.0.12
Code:
./configure --sbin-path=/usr/local/sbin --with-http_ssl_module
Code:
make
sudo make install
Code:
sudo /usr/local/sbin/nginx
That’s it right? No not exactly.
Nginx won’t auto start on reboots. So let’s make it happen.
First kill Nginx,
Code:
sudo kill `cat /usr/local/nginx/logs/nginx.pid`
Code:
sudo nano /etc/init.d/nginx
Code:
#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
exit 1
;;
esac
exit 0
Code:
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults
Code:
sudo nano /usr/local/nginx/conf/nginx.conf
Code:
user www-data www-data;
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 5;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /usr/local/nginx/sites-enabled/*;
}
Let’s create Virtual Host File Structure & Symlinks,
We need 2 new folders
Code:
sudo mkdir /usr/local/nginx/sites-available
sudo mkdir /usr/local/nginx/sites-enabled
Code:
sudo nano /usr/local/nginx/sites-available/default
Code:
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}
Code:
sudo ln -s /usr/local/nginx/sites-available/default /usr/local/nginx/sites-enabled/default
Code:
sudo /etc/init.d/nginx start
That’s it! Nginx is now working properly. Remember this is 5th post of my Nginx series. All other tutorials are available at my blog.
Source - Install and Configure Nginx Web Server on Ubuntu VPS