howtodownload

howtodownload
cach down

Thứ Bảy, 12 tháng 10, 2013

Cấu hình lighttpd trên Centos 5.6

MÌnh đã từng có 2 bài lab về cấu hình webserver đó là cấu hình webserver apache và Nginx. Trong bài lab ngắn này mình sẽ hướng dẫn các bạn cài đặt và cấu hình lighttpd trên centos 5.6 .

Lighttpd là một webserver chạy khá là tốt, an toàn, nhanh và cực kỳ nhẹ.


Các bạn xài thằng này đi sẽ thấy nó tuyệt vời chả kém gì 2 webserver kể trên.

1.Cài đặt :

Hiện nay lighttpd đã có version 1.5 với việc hỗ trợ chuẩn h264(mp4) streaming đẳng cấp cao hơn so với version 1.4 chỉ hỗ trợ h263(flv) streaming. Ngoài ra còn 1 module nữa khá hữu ích đối với bạn đó upload_progress cho phép bạn quan sát được quá trình upload bao gồm bao nhiêu byte/byte, thời gian như thế nào.....

Để cài đặt webserver bạn gõ lệnh sau nha.

yum install -y lighttpd

Việc cài đặt khá dễ dàng phải không nào !!!!

2.Cấu hình :

File cấu hình dịch vụ nằm ở đường dẫn /etc/lighttpd/

Bạn dùng lệnh vi (hoặc vim) để mở file lighttpd.conf lên.Chúng ta sẽ vào đây xem các option của nó và giải thích nhé.

vim /etc/lighttpd/lighttpd.conf
PHP Code:
#thu muc chua log
var.log_root    = "/var/log/lighttpd"
# thu muc chua source web
var.server_root = "/srv/www"
#
var.state_dir   = "/var/run"
# thu muc chua file mau
var.home_dir    = "/var/lib/lighttpd"
# thu muc chua file cau hinh
var.conf_dir    = "/etc/lighttpd"
#
var.vhosts_dir  = server_root + "/vhosts"
# thu muc chua cache web
var.cache_dir   = "/var/cache/lighttpd"

##
var.socket_dir  = home_dir + "/sockets"

##
include "modules.conf"

##
#######################################################################

#######################################################################
##
##  Cau hinh co ban
## ---------------------
# port web server.mac dinh la port 80
server.port = 80

# su sung IPv6.mac dinh la off.
server.use-ipv6 = "disable"
# user va group cua lighttpd.user va group nay phai co quyen tren file cau hinh 
# va thu muc chua source web de dich vu co quyen chay.
server.username  = "lighttpd"
server.groupname = "lighttpd"

## 
## enable core files.
##
#server.core-files = "disable"

##
## Document root
##
server.document-root = server_root + "/lighttpd"

##
## The value for the "Server:" response field.
##
## It would be nice to keep it at "lighttpd".
##
#server.tag = "lighttpd"

##
## store a pid file
##
server.pid-file = state_dir + "/lighttpd.pid"

##
#######################################################################

#######################################################################
##
##  Logging Options
## ------------------
## duong dan file log khi dich vu chay bi loi.
##
server.errorlog             = log_root + "/error.log"

##
## neu ban muon lighttpd ghi log vao syslog thi bo dau # o dong duoi.
#server.errorlog-use-syslog = "enable"

##
## file cau hinh log ghi nhan su truy cap.
## 
include "conf.d/access_log.conf"

##
include "conf.d/debug.conf"


#######################################################################

#######################################################################
##
##  Tuning/Performance
## --------------------
##
##
## set the event-handler (read the performance section in the manual)
##
## possible options on linux are:
##
## select
## poll
## linux-sysepoll
##
## linux-sysepoll is recommended on kernel 2.6.
##
server.event-handler = "linux-sysepoll"

##
## Ve co ban thi giao dien mang chi cho doc va viet.
## Nhieu he dieu hanh hien dai cung cap syscalls rieng de giup mang
## chuyen file cang nhanh cang tot.
##
## linux-sendfile la danh cho viec goi file nho.
## writev         la danh cho viec chuyen  nhieu file lon.
##
server.network-backend = "linux-sendfile"

##
## So tap tin mo ta duoc open.moi request php chi can 3 tap tin mo ta la :handle-TCP/IP-with-user , socket-to-FastCGI và Check-wheher-a-file-exists 
## voi server chiu tai cao thi nen tang so nay len.tuy thuoc cau hinh phan cung.

server.max-fds = 2048

##
## Stat() call caching.
##
## lighttpd can utilize FAM/Gamin to cache stat call.
##
## possible values are:
## disable, simple or fam.
##
server.stat-cache-engine = "simple"

## so ket noi toi da ma server cho phep.
## de an toan thi so nay bang 1/2 so server.max-fds
##
server.max-connections = 1024

##
## so thoi gian song cua ket noi.
## cho toi khi server xem la no dang nhan roi.
##
## mac dinh la 5 giay
##
#server.max-keep-alive-idle = 5

##
## so thoi gian song cua ket noi cho toi khi server ngat ket noi.
##
## mac dinh la 16 giay
##
#server.max-keep-alive-requests = 16

##
## kich co file toi da ma client duoc phep yeu cau.
## mac dinh la khong gioi han.
##
## tai len server cua ban co the lon hon con so nay.
##
#server.max-request-size = 0

##
## Thoi gian doc tu socket truoc khi server cho ket noi la ranh roi.
##
## mac dinh la 60 giay
##
#server.max-read-idle = 60

##
## Thoi gian doc tu socket truoc khi server cho ket noi la ranh roi.
##
## mac dinh la  360 giay
##
#server.max-write-idle = 360

##
##  Dinh hinh luu luong 
## -----------------
##
## file mau /usr/share/doc/lighttpd/traffic-shaping.txt
##
## gia tri la kilobyte/giay.
##
## gioi han luu luong truy cap.
##
## tren server.
## mac dinh la 128kB/s
##
#server.kbytes-per-second = 128

##
## tren ket noi.
## mac dinh la 32kB/s
##
#connection.kbytes-per-second = 32

##
#######################################################################

#######################################################################
##
## file chay lighttpd.ban phai tao file giong the nay de lighttpd doc duoc.
## co the them cac dinh dang khac nhu index.php
index-file.names += (
  "index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)

##
## cac duoi mo rong bi deny
## 
url.access-deny             = ( "~", ".inc" )

##
## khong xu ly doi voi file pdf.
## cach sua loi nay trong Acrobat Reader plugin.
##
$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}

##
## url handling modules (rewrite, redirect)
##
#url.rewrite                = ( "^/$"             => "/server-status" )
#url.redirect               = ( "^/wishlist/(.+)" => "http://www.example.com/$1" )

##
## both rewrite/redirect support back reference to regex conditional using %n
##
#$HTTP["host"] =~ "^www\.(.*)" {
#  url.redirect            = ( "^/(.*)" => "http://%1/$1" )
#}

##
## which extensions should not be handle via static-file transfer
##
## .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
##
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi" )

##
## error-handler for status 404
##
#server.error-handler-404   = "/error-handler.html"
#server.error-handler-404   = "/error-handler.php"

##
## Format: <errorfile-prefix><status-code>.html
## -> ..../status-404.html for 'File not found'
##
#server.errorfile-prefix    = "/srv/www/htdocs/errors/status-"

##
## mimetype mapping
##
include "conf.d/mime.conf"

##
## cau hinh danh sach thu muc.
##
include "conf.d/dirlisting.conf"

##
## cho phep lien ket mem ?
## 
server.follow-symlink = "enable"

##
## ep cac ten file thanh chu thuong ?
##
#server.force-lowercase-filenames = "disable"

##
## thu muc chua file upload.ban co the thay doi duong dan nay.
##
server.upload-dirs = ( "/var/tmp" )

##
#######################################################################


#######################################################################
##
## ho tro ssl
## ------------- 
##
## To enable SSL for the whole server you have to provide a valid
## certificate and have to enable the SSL engine.::
##
##   ssl.engine = "enable"
##   ssl.pemfile = "/path/to/server.pem"
##
## The HTTPS protocol does not allow you to use name-based virtual
## hosting with SSL. If you want to run multiple SSL servers with
## one lighttpd instance you must use IP-based virtual hosting: ::
##
##   $SERVER["socket"] == "10.0.0.1:443" {
##     ssl.engine                  = "enable"
##     ssl.pemfile                 = "/etc/ssl/private/www.example.com.pem"
##     server.name                 = "www.example.com"
##
##     server.document-root        = "/srv/www/vhosts/example.com/www/"
##   }
##

## If you have a .crt and a .key file, cat them together into a
## single PEM file:
## $ cat /etc/ssl/private/lighttpd.key /etc/ssl/certs/lighttpd.crt \
##   > /etc/ssl/private/lighttpd.pem
##
#ssl.pemfile = "/etc/ssl/private/lighttpd.pem"

##
## optionally pass the CA certificate here.
##
##
#ssl.ca-file = ""

##
#######################################################################

#######################################################################
##
## cau hinh virtualhost.
##
#include "conf.d/config.conf"
include_shell "cat /etc/lighttpd/vhosts.d/*.conf"
##
#######################################################################  
Bây giờ các bạn vào thư mục chứa source web là /srv/www/lighttpd/ để tạo 1 file trang chủ.

Bạn dùng lệnh sau để tạo file trang chủ với nội dung tuỳ ý.

vim /srv/www/lighttpd/index.html

Sau đó bạn lưu lại và trên server bạn mở một trình duyệt web lên để test với địa chỉ là localhost hoặc ip của webserver.


Để có thể cho client truy cập với 1 tên miền xác định thì bạn có thể cấu hình DNS server và cho client trỏ về dns server.Sau đó mở trình duyệt và truy cập với domain mà mình đã tạo.

PS: bạn có thể cài mysql và php5 để server của bạn hoàn hảo hơn.sắp tới mình sẽ demo loạt bài viết về cấu hình một server hoàn hảo.các bạn chú ý xem nhé.

Không có nhận xét nào:

Đăng nhận xét