Engels (wijzigen) 
Installeren en configureren nginx web server, het instellen van het standaard bestand structuur, dan is het opzetten van een vhost bestand met symlink is het onderwerp van deze copy / paste how-to. Dus open dat CLI en ik zal uitleggen.
Dus we klaar om een attractie te installeren, nginx (uitgesproken als "motor-x"). Maar waarom? Is het niet de beste Apache web server?
Apache heeft me goed gediend voor jaren, zowel lokaal als op afstand hosts, en is nog steeds een wenselijke keuze voor vele grote sites.
Maar, kinda als Ubuntu, FireFox en jQuery, is er een nieuwe jongen in de stad, en het is slanker, eenvoudiger te configureren en te gebruiken, en sneller te bedienen. Voer de nginx web server.
In 20 copy / paste stappen .. van nul tot held, lege doos om cute-als Linux-server.
Scroll naar beneden voor de volledige reeks index.
Dus, hey, schuur gedeeld en viva virtueel! Hope it helps. The_guv
Watch the, er, guvideo voor een beter idee van hoe dit te doen.
Check out the_guv's YouTube-kanaal op http://youtube.com/guvnrDOTcom
... of als u niet kan worden last van, of zelfs als je kunt, is hier de details ...
Ik ben het niet belijden als een deskundige, maar iemand die ultra-grondig onderzocht. Ik concentreerde me vooral op de twee meest populaire, best gevestigd web servers, Apache en Lighttpd, en de jonge Turk alternatief, nginx, waarover geekdom is allemaal aflutter. Hier is een overzicht van mijn belangrijkste bevindingen: --
Ik gebruik dit licht-gewicht server voor mijn bron zware WordPress blog, guvnr.com, en ik ben onder de indruk van haar solide prestaties. Ook belangrijk is, is het niet hebben dat Windows-achtige trend, een Apache aandoening ook van het verspillen van middelen door het draaien van een bos van de diensten die ik gewoon niet nodig hebt.
Neem niet mijn woord. Je moet niet, omdat ik niet hebben uitgevoerd elke benchmark tests. Google iets als Apache vs nginx "of nginx vs Lighttpd en hebben een te lezen. En hier is de nginx wiki.
Er zijn twee manieren om software te installeren op Linux met behulp van de geïntegreerde installatie gereedschap of broncode.
Normaal gesproken, installeren we intern, met iets als geschiktheid van de Linux-installer '', maar omdat dit zo'n belangrijk onderdeel van onze VPS, ik ga u laten zien hoe het installeren van de bron. Deze methode duurt iets langer, maar het is de moeite waard omdat we een veel meer zal moeten up-to-date versie.
.. Met een web server moeten we niet afraffelen. Dat zou zijn als het kopen van een gele Ferrari.
Eerst omhoog, moeten we enkele afhankelijkheid bestanden: --
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
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`
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
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/*;
}
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.
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.
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 ..
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
Install/Upgrade WORDPRESS with SUBVERSION - VPS Bible #15 - GUVNR June 9th, 2009 at 11:38 am
[...] Part 11: * Nginx (better than Apache) Web Server [...]
Configure NGINX Multi-Site Virtual Hosts - VPS Bible Pt 13 - GUVNR June 9th, 2009 at 11:38 am
[...] Part 11: * Nginx (better than Apache) Web Server [...]
mnyman June 10th, 2009 at 6:34 pm
This has been really amazing, so thanks a bunch.
For those of us who are completely new at this, I get a warning when I "boot it up again" that says:
Starting nginx: [warn]: duplicate MIME type "text/html" in /usr/local/nginx/conf/nginx.conf:21
Looking in the file, I couldn't find anything duplicating. Do you know why this would happen? Having errors like these explained is especially comforting when we don't fully understand what is going on. Thanks again for all your work on this.
the_guv June 10th, 2009 at 11:10 pm
Hi Mnyman,
Hmmn, sorry to say, looks like you've made a typo. Unless .. is there any discrepancy between what I have set down from the start to where you are, and what you have done?
Tell you what though .. click on Contact and send me an email with the content of nginx.conf, and I'll take a look.
And to create a directory in which to store the Nginx package:-
Change to that directory:-
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:-
Unzip it:-
Go into the new unzipped folder:-
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):-
Install this baby:-
Kick it up:-
And test it by popping your IP address in a web browser. You should see "Welcome to nginx!"
Now stop it:-
Have Nginx Start, Restart or Stop When Required
This is important, for example, upon reboot. We need a script for this. Create a file:-
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 0Then give the file permissions and make the script run on reboot, else start/stop/restart when required:-
nginx.conf - Configuring Nginx
Now open the Nginx configuration file:-
...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:-
...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:-
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:-
Boot it up again:-
...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
If you liked that ...
Set Up Unmanaged VPS (4 Newbies) - Part 13: Serve Multiple Sites & Blogs with Virtual Hosts
Set Up Unmanaged VPS (4 Newbies) - Part 10: Prepare Linux Server for Email with Postfix
Set Up Unmanaged VPS (4 Newbies) - Part 14: Tweak Nginx for WordPress - Pretty URLs & WP Super Cache
Maintain Unmanaged VPS - Part 5: Get phpMyAdmin Working with Nginx
Set Up Unmanaged VPS (4 Newbies) - Part 1: VPS (Virtual Private Server) vs Shared vs Dedicated
Set Up Unmanaged VPS (4 Newbies) - Part 17: Nginx Control Panel Workarounds
... maybe you'll like these?