.

Installare NGINX (meglio di Apache o Lighttpd) - VPS Bibbia PT 11

English Italiano (Change)
  • Digg
  • Twitter
  • Technorati
  • del.icio.us
  • Facebook
  • MySpace
  • Reddit
  • StumbleUpon
  • LinkedIn
  • email

Set Up VPS Unmanaged (4 principianti) - Parte 11: Nginx (meglio di Apache) Web Server

Installare Nginx - Nginx logo

Installazione e configurazione del server web Nginx, modificando la struttura dei file di default, quindi la creazione di un file vhost con link simbolico è il soggetto di questa copia / incolla how-to. Così si aprono che CLI e ti spiego.

Quindi siamo pronti a installare una attrazione, Nginx (si pronuncia "motore-x"). Ma perché? Non è il server Apache migliori web?

Apache ha servito bene da anni, sia in locale che su host remoti, ed è ancora una scelta desiderabile per molti siti di grandi dimensioni.

Ma, kinda like Ubuntu, FireFox e jQuery, c'è un nuovo capretto in città, ed è più snello, semplice da configurare e utilizzare, veloce e servire. Inserisci il web server Nginx.

Istituire un VPS gestito (4 Newbies) .. La Bibbia VPS

In 20 copia / incolla passi .. da zero a hero, vuota la casella di cute, come server Linux.

Scorrere verso il basso per l'indice completo della serie.

Così, hey, rimessa condivisi e viva virtuale! Hope it helps. The_guv

Video: Installare e configurare Nginx Web Server

Watch the, er, guvideo per una migliore idea di come fare questo.

Check out canale YouTube di the_guv a http://youtube.com/guvnrDOTcom

... o se non si può perdere tempo con quella, o anche se si può, ecco i dettagli ...

Perché scegliere Nginx? Perché non Apache o Lighttpd?

Io non professano di essere un esperto, solo chi ha le ricerche ultra-bene. Mi sono concentrato principalmente sulle due più popolari, i migliori stabilito web server, Apache e Lighttpd, e l'alternativa Giovani Turchi, Nginx, su cui è Geekdom tutti svolazzante. Ecco una sintesi delle mie scoperte chiave: --

  • Apache è bloatware, il caricamento dei moduli non utilizzati, che spreco di risorse
  • Lighttpd perdite RAM male
  • Nginx parametri di riferimento il più veloce, utilizzando le risorse almeno

Ho usato questa luce server di peso per la mia risorsa-blog WordPress pesanti, guvnr.com, e sono impressionato con le sue prestazioni. Anche importante, non è che Windows, come tendenza, una afflizione Apache troppo, di spreco di risorse eseguendo un gruppo di servizi che io non ho bisogno.

Non prendere la mia parola. Non si dovrebbe, perché non ho effettuato alcun test di benchmark. Google qualcosa come Apache vs Nginx "o Nginx vs Lighttpd e hanno un letto. Ed ecco la Nginx Wiki.

Getting the Latest Version Nginx

Ci sono due modi per installare il software su Linux, utilizzando gli strumenti integrati di installazione o dal codice sorgente.

Normalmente, si installa internamente, con qualcosa come l'attitudine del programma di installazione di Linux ', ma perché questa è una componente importante della nostra VPS, ho intenzione di mostrare come installare dai sorgenti. Questo metodo richiede un po 'di più, ma ne vale la pena, perché avremo più molto up-to-versione aggiornata.

.. Con un server web, non si dovrebbe tagliare gli angoli. Che sarebbe come comprare una Ferrari gialla.

In primo luogo, abbiamo bisogno di alcuni file di dipendenza: --

sudo aptitude -y install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

And to create a directory in which to store the Nginx package:-

mkdir ~/sources

Change to that directory:-

cd ~/sources/

Now we get the latest stable Nginx release, nginx-0.7.62 *.

* As of September 2009, edited by the_guv. You should still check it is still the latest, here , and ammend the filename accordingly:-

wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz

Unzip it:-

tar -zxvf nginx-0.7.62.tar.gz

Go into the new unzipped folder:-

cd nginx-0.7.62

Installing and Testing Nginx

Compile with two options; where to install it, and including 'ssl' (to enable 'https' for secure connections, ie shopping and stuff):-

./configure --sbin-path=/usr/local/sbin --with-http_ssl_module

Install this baby:-

make
sudo make install

Kick it up:-

sudo /usr/local/sbin/nginx

And test it by popping your IP address in a web browser. You should see "Welcome to nginx!"

Now stop it:-

sudo kill `cat /usr/local/nginx/logs/nginx.pid`

Have Nginx Start, Restart or Stop When Required

This is important, for example, upon reboot. We need a script for this. Create a file:-

sudo nano /etc/init.d/nginx

And paste this within:-

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

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

Then give the file permissions and make the script run on reboot, else start/stop/restart when required:-

sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

nginx.conf - Configuring Nginx

Now open the Nginx configuration file:-

sudo nano /usr/local/nginx/conf/nginx.conf

...and strip out all the content, delete the lot. CTRL-K is the easy way to do that, if you were wondering.

And replace with this:-

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/*;
}

Creating the Virtual Host File Structure & Symlinks

The Nginx file structure is pretty messy for multiple sites, so we'll sort that.

First, layout some new folders:-

sudo mkdir /usr/local/nginx/sites-available
sudo mkdir /usr/local/nginx/sites-enabled

...the first is for our virtual host (vhost) files, the second for their corresponding symlinks which will be referenced by Nginx' config file.

What are vhosts & symlinks?

You have one of each per domain, and one of each for the default settings.

The symlink, or symbolic link, references the web server to the virtual host file.

The vhost file is a configuration file. It tells the web server, for example, things like where the web files live or the kind of URI structure you want.

For now, we need a default vhost file, and that goes in the sites-available folder. So:-

sudo nano /usr/local/nginx/sites-available/default

Now paste this:-

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;
            		   }
		}

And enable it with this symlink:-

sudo ln -s /usr/local/nginx/sites-available/default /usr/local/nginx/sites-enabled/default

Boot it up again:-

sudo /etc/init.d/nginx start

...and check for that "Welcome..." page again, using your IP in a web browser.

Splendid. All pretty. And pretty well organised.

Moving Along

So that's Nginx up and running.

In Part 12 of this series Set Up an Unmanaged VPS (4 Newbies) I'm taking a quick detour, setting up FileZilla so we've got a Secure FTP (SFTP) connection. That'll be handy to help demonstrate Part 13, when we create another folder structure, this time for our sites and blogs, and pop up a couple of test pages.

Then, in Part 13, I'll show you how to use Subversion to more easily install and upgrade platforms and their modules/plugins. I'll example the popular WordPress scenario - and while we're about it we'll sort out WordPress caching and friendly-URLs.

And then, this, that, the other. Cue index ..


SETUP an Unmanaged VPS (4 Newbies) .. The V-P-S Bible

Serve multi sites & blogs on a budget .. at the fastest possible speed .. with the least downtime .. in the most secure environment .. and future-proofed for easy admin.

That's what the VPS Bible is about, stepped out in simple copy & paste guides.

From high traffic WordPress blogs to startup web hosts, here's what you need.

Set it up?   Click here for the 21 part follow-up .. V-P-S Admin

  1. * Includes video tutorial.

  2. Not linked = not published. Won't be long. Fix a feed for updates.


If you liked that ...

.