首先,下載nginx的Key,並加入Key
wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key
編輯容器清單
sudo vim /etc/apt/sources.list
在最底下加入下載版本的來源以及名稱,我用的版本是13.10名稱為saucy
deb http://nginx.org/packages/ubuntu/ saucy nginx deb-src http://nginx.org/packages/ubuntu/ saucy nginx
更新容器清單
sudo apt-get update
更新完容器就可以下載nginx
sudo apt-get install -y nginx
安裝完成後,在瀏覽器網址列鍵入IP即可看到這個畫面
不過我們先來看一下nginx預設配置檔
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
由上面配置檔得知以下幾件事情
- 根目錄為/usr/share/nginx/html
- 支援的檔案為html和htm
- 發生500、502和503以及504錯誤時會導向到50x.html
把404的註解拿掉,輸入
sudo touch 404.html /usr/share/nginx/html/ & sudo vim /usr/share/nginx/html/404.html
把下方文字填入404.html裡面
C.Y. Fang
nginx重新載入配置
sudo nginx -s reload
在瀏覽器輸入IP/test,就會顯示如下圖畫面
nginx已經在2014.3月取得了17.65%的使用率了XD
調校的好,或許以後就不會在用Apache了
參考資料:
http://zh.wikipedia.org/wiki/Nginx
http://nginx.org/en/
http://ithelp.ithome.com.tw/question/10122157?tag=ithome.nq
http://nginx.org/en/docs/install.html
http://nginx.org/en/linux_packages.html
http://nginx.org/en/linux_packages.html#distributions
http://nginx.org/en/docs/beginners_guide.html#control
http://manpages.ubuntu.com/manpages/precise/en/man5/sources.list.5.html
http://news.netcraft.com/archives/2014/03/03/march-2014-web-server-survey.html