安装Nginx的(优于阿帕奇或Lighttpd) -车辆定位系统圣经铂11

English 英国(更改)
  • Digg
  • Twitter
  • Technorati
  • del.icio.us
  • Facebook
  • MySpace
  • Reddit
  • StumbleUpon
  • LinkedIn
  • email

最多(4新成员) -第11部分:Nginx的非托管车辆定位系统设置(优于阿帕奇)Web服务器

安装Nginx的- Nginx的标志

Nginx的安装和配置Web服务器,调整默认的文件结构,然后建立一个符号链接虚拟主机文件是本复制/粘贴操作方法问题。 因此,开放,CLI和我将解释。

所以,我们正在准备安装一个明星的吸引力,Nginx的(发音为“引擎- x”的)。 但为什么呢? 阿帕奇是不是最好的Web服务器?

阿帕奇一直担任我好多年,在本地和远程主机上,并且仍然是许多大型站点理想的选择。

但是,如Ubuntu,火狐和jQuery有点儿,有一个小镇新来的孩子,它的精简,简化配置和使用,和更快的服务。 输入Nginx的Web服务器。

成立了(4新成员)..非托管车辆定位系统 圣经的车辆定位系统

在20个复制/粘贴操作.. 从零到英雄,空白方块可爱的Linux服务器。

向下的全系列指数。

所以,嘿,下跌共享与虚拟万岁!希望有所帮助。the_guv

视频:Nginx的安装和配置Web服务器

看,呃,guvideo了如何更好地做到这一点的想法。

退房the_guv的YouTube在http://youtube.com/guvnrDOTcom通道

...或者如果您不能罢的,或者即使可以,这里的细节...

为什么选择Nginx的? 为什么不阿帕奇或Lighttpd?

我不自称是专家,只是谁也有人研究超彻底。 本人主要集中在两个最流行,最成熟的网络服务器,Apache和lighttpd的,而年轻的土耳其人替代,Nginx的,对此geekdom是所有发抖。 以下是我的主要结论摘要: -

  • Apache是英国媒体,装载未使用的模块,浪费资源
  • lighttpd的内存泄漏严重
  • Nginx的基准速度最快,使用最少的资源

我一直在使用我的资源这个重量轻,服务器重WordPress博客,guvnr.com,和我同其稳健的表现留下深刻印象。 另外重要的是,它没有的Windows类似的趋势,一个Apache苦恼过,浪费运行的服务,我只是一堆不需要的资源。

不要把我的话。 你不应该,因为我还没有执行任何基准测试。 谷歌队如 Apache Nginx的事“或Nginx的队lighttpd的并有阅读。和这里的Nginx的维基

Nginx的获取最新版本

有两种方法上安装Linux软件,使用集成的安装工具或从源代码中。

通常情况下,我们在内部安装,使用Linux安装程序一样'aptitude'的,而是因为这是我们这样一个车辆定位系统的重要组成部分,我将告诉你如何从源文件安装的东西。 这种方法需要一点时间,但它是值得的,因为我们将有一个更为了最新的版本。

.. 与Web服务器,我们不应该偷工减料。 这将是如同你买了黄色的法拉利。

首先,我们需要一些相关文件: -

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 ...
  • Set Up Unmanaged VPS (4 Newbies) - Part 13: Serve Multiple Sites & Blogs with Virtual Hosts

    Now to add sites & blogs to our powerful web server, using vhost (virtual host) files and symlinks. We'll create a site file structure, add users with groups & permissions, tweak Nginx with FastCGI [...]
  • Set Up Unmanaged VPS (4 Newbies) - Part 14: Tweak Nginx for WordPress - Pretty URLs & WP Super Cache

    For the blog platform WordPress to work properly with Nginx we need to tweak the web server configuration. This tutorial will enable both caching - integrating the WP Super Cache plugin - and activate pretty [...]
  • Set Up Unmanaged VPS (4 Newbies) - Part 10: Prepare Linux Server for Email with Postfix

    In this tutorial we'll configure an email function for the VPS. That's not to turn this Linux system into a mail server .. but to allow our web apps to be able to send and automate outgoing email. If you recall [...]首先,我们需要一些相关文件: -
    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 ...
    ... maybe you'll like these?

.