Kiến Thức Linux Thủ Thuật

Hướng Dẫn Cài Đặt Nginx Từ Source

congdonglinux-NGINX-logo

1. cài đặt các gói cần thiết

*** Ubuntu

$ apt-get install apt-utils autoconf automake build-essential git libcurl4-openssl-dev libgeoip-dev liblmdb-dev libpcre++-dev libtool libxml2-dev libyajl-dev pkgconf wget zlib1g-dev libssl-dev
*** Centos
$ yum groupinstall -y 'Development Tools' && yum install -y epel-release perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel

2/ Tải  và build từ source code

truy cập vào trang http://nginx.org/en/download.html để tải bản cài đặt mới nhất. Sau khi tải về, tiến hành giải nén và chạy các câu lệnh sau:
$ ./configure \
--prefix=/webserver \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail --with-mail_ssl_module \
--with-file-aio --with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module

$ make
$  make install
$ mkdir –p /var/cache/nginx
$ touch /var/cache/nginx/client_temp
$ nginx
mở trình duyệt web, truy cập địa chỉ IP của máy bạn để kiểm tra xem Nginx đã cài đặt thành công hay chưa.

3. Tích Hợp với Systemd

tạo một file mới nginx.service
$ vim /lib/systemd/system/nginx.service
copy và paste những nội dung bên dưới vào file mới tạo.
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/webserver/nginx.pid
ExecStartPre=/webserver/sbin/nginx -t
ExecStart=/webserver/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
save file lại và kill tiến trình nginx đã chạy trước đó với câu leenhj:
$ killall nginx
start nginx với systemd
$ systemctl start nginx
Check status
$ systemctl status nginx
$ sudo systemctl enable nginx
Chúc Các Bạn Thành Công.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !