xây dựng vpsm nginx

18 231 0
xây dựng vpsm nginx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

 CÀI ĐẶT VPS  Các thành phần sẽ cài  Cài đặt Nginx, ngx_pagespeed và cấu hình tối ưu  Cài đặt và tối ưu Mariadb  Cài đặt và tối ưu php-fpm  Phpmyadmin  VSFTPD  Xcache  CSF  Bonus : Bảo mật nginx cơ bản  Các bước chuẩn bị.  Add các repo cần thiết rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6- 8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh http://www6.atomicorp.com/channels/atomic/centos/6/i386/RPMS/atomic- release-1.0-19.el6.art.noarch.rpm II. Cài các libs cần thiết BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 1  yum -y install gcc-c++ pcre-dev pcre-devel zlib-devel make openssl-devel III. Tạo user cho nginx groupadd nginx useradd -g nginx -d /dev/null -s /sbin/nologin nginx  Tiến hành cài đặt  Cài đặt nginx và ngx_pagespeed Chạy lần lượt các lệnh sau cd /opt wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.9.32.2-beta.zip unzip release-1.9.32.2-beta.zip cd ngx_pagespeed-release-1.9.32.2-beta wget https://dl.google.com/dl/page-speed/psol/1.9.32.2.tar.gz tar -xvf 1.9.32.2.tar.gz cd /opt wget http://nginx.org/download/nginx-1.7.9.tar.gz tar -xvf nginx-1.7.9.tar.gz cd nginx-1.7.9 ./configure prefix=/usr/share/nginx sbin-path=/usr/sbin/nginx with- http_ssl_module conf-path=/etc/nginx/nginx.conf with-http_gzip_static_module with-http_realip_module group=nginx user=nginx pid-path=/var/run/nginx.pid with-http_stub_status_module add-module=/opt/ngx_pagespeed-release-1.9.32.2- beta make make install 1. Tạo file khởi động Tải file sau đây về và quăng vào /etc/init.d https://drive.google.com/file/d/0B5GXJ8MAIvQqRWZiNEl1aExuZzA/view?usp=sharing - Chmod cho file nginx BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 2  chmod +x /etc/init.d/nginx - Run tiếp các lệnh sau mkdir -p /var/cache/ngx_pagespeed mkdir -p /var/log/nginx chown -R nginx:nginx /var/cache/ngx_pagespeed chown -R nginx:nginx /var/log/nginx - Khởi động nginx service nginx start chkconfig levels 235 nginx on 2. Cấu hình Truy cập /etc/nginx tải 2 file sau về và chép đè vào https://drive.google.com/file/d/0B5GXJ8MAIvQqOE5oNDZab3JpUWM/view?usp=sharing https://drive.google.com/file/d/0B5GXJ8MAIvQqRDdPa1BEX2Nzb0U/view?usp=sharing 3. Tạo virtual host và thư mục public_html - Tạo thư mục conf.d bằng lệnh sau hoặc có thể dùng winscp để tao: mkdir -p /etc/nginx/conf.d - Tạo thư mục public_html mkdir -p /home/domain-của-bạn/public_html mkdir /home/domain-của-bạn/logs chmod 777 /domain-của-bạn/logs chown –R nginx:nginx /home/domain-của-bạn - Truy cập vào thư mục conf.d và tạo một file bất kỳ với đuôi là .conf ví dụ mình tạo file quylevhb.conf BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 3  server { server_name www.domain-của-bạn; rewrite ^(.*) http://domain-của-bạn-không-có-www $1 permanent; } server { listen 80; access_log off; error_log off; # error_log/home/domain-của-bạn/error.log; root /home/domain-của-bạn/public_html; index index.php index.html index.htm; server_name domain-của-bạn-không-có-www; location / { try_files $uri $uri/ /index.php?$args; } include /etc/nginx/ngx_pagespeed.conf; # bật ngx_pagespeed location ~ \.php$ { root /home/domain-của-bạn/public_html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } Thay đường dẫn và server name của các bạn vào là được. Nếu các bạn muốn ghi log thì bỏ dấu # ở đoạn # error_log/home/domain-của-bạn/error.log; và sửa error_log off; thành error_log on; - Khởi động lại nginx service nginx restart BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 4   Cài đặt mariadb  Add repo  !"!# $% !&'( &)*#+),,- ##.&)*#/0'101234'( ##).& )567)89:;!)<);)=!>!'( !)?+@:.:)=! >!A!B):C)*#.)D9EF>! !)?);) !.)=!>!9B9G!# &)*#+),,- H Cài đặt !'('(! BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 5  BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 6  I Đặt mật khẩu và bảo mật mysql )J!) K ).!#K! KLL!M! BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 7     !"#$%&' (#$ )""&*($"+*,$'-.$"" % ,$(-'"()""&,%()""&& // 0% ",$"($ .$")""(+ #$)""&*1*23Bấm Enter4 5%"$##""*$ ,$")""&%6-!+++ !()""&"$"(/,# !( $"&($())$("+ )""&7384Y &)""&3Nhập mật khẩu bạn muốn4 9&)""&3Nhập lại mật khẩu4 ""&$)"$##""*$ ,  !)- !/ "++ +++$##"" ,*$ %" (",6$"$"% &!,  !&($(-!(-$"##$#* (6+("" ,*"!%60("  !/"6(+$"($ 6-(6/*6-! )$#-6+ 6-,6$"$""7384Y +++$##"" 6 ,%"($  ,/ &##*6' # ("'+(" "$"("6#!$""()""&*6(&0+ " & !6 ,7384Y +++$##"" ,*$ %#6"&(/"6'"'(,# ##""+("" " ,*"!%"($ /6- /*6-!)$#-6+ 6-"/"##""7384Y 9))!"/"+++ +++$##"" 96-!)- !""/"+++ +++$##""  !()- !/ "& "$( #(!"6"* & 0:#66 ,+  )- !/ "&7384Y +++$##""  !$)+++  *,$'-#6)  *(/-")"%,$ " "($ &/"#$+ (0"*$"! BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 8  - Tối ưu MariaDB 6;< 8#86,+#*-=#),>?@$!=,-=AB!includedir /etc/my.cnf.d 36,"C 4 0,D/$:EFGG / D##(EHGGG "D/$:D"IEJ D/$:D"IEK DD/$:D"IEL 6,"6D"D/$:D"IEMH 6ND##"EHGG C$,D##(D,)EO C$,D##(D 6EF C$,D##(D"IEFGG 6)D/ D"IEKG 6ND()D/ D"IEKG (D##(D"IEMH  5(;>@! ?6,"C "-#6,"C "  Cài đặt php-fpm  Cài đặt yum -y enablerepo=remi install php-common php-fpm php-gd php-mysql php-pdo php-xml php-mbstring php-mcrypt php-pecl-apc php-curl php-soap Chú ý: lệnh này sẽ cài đặt php 5.4 nếu muốn cài php 5.6 các bạn chạy lệnh BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 9  yum enablerepo=remi,remi-php56 -y install php php-common php-fpm php-mysql php-gd php-xml php-mbstring php-mcrypt php-pdo php-soap - Khởi động php-fpm service php-fpm start chkconfig levels 235 php-fpm on BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 10 [...]... https://drive.google.com/file/d/0B5GXJ8MAIvQqZEdGVWZYQTBKOXM/view? usp=sharing - Chạy các lệnh sau: mkdir –p nginx: nginx /var/lib/php/session chown -R nginx: nginx /var/lib/php service php-fpm restart Cài đặt phpmyadmin IV 1 Cài đặt yum enablerepo=remi -y install phpMyAdmin 2 Cấu hình mở file vhost (etc /nginx/ conf.d/abc.conf) abc.conf: Tên file vhost của bạn Thêm vào cuối file đoạn rule sau server { listen... chkconfig level 235 csf on service csf restart VIII Bảo mật cơ bản cho nginx BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 17 Q 1 Chmod - Chmod thư mục: home, domain-của-bạn, public_html, etc /nginx, etc /nginx/ conf.d, - etc/php-fpm.d về 711 Chmod tất cả các file trong thư mục /etc /nginx, /etc/php-fpm.d, /etc/phpMyAdmin và /etc /nginx/ conf.d về 600 Chmod file /etc/phpMyAdmin/ config.inc.php và /etc/php.ini,... "Private"; auth_basic_user_file /etc /nginx/ conf/.htpasswd; } Thay /admincp bằng path thư mục admincp của bạn Tạo file htpasswd trong thư mục /etc /nginx Để tạo các bạn dung lệnh sau htpasswd -bc /etc /nginx/ .htpasswd myusername mypassword Ví dụ: htpasswd -bc /etc /nginx/ .htpasswd quylevhb 123456 IX Tài liệu Các bạn có thể xem them tại: http://quylevhb.blogspot.com/search/label /Nginx BLOG HACKING & SECURITY:... Cấu hình BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 11 Q - Mở file /etc/php-fpm.d/www.conf thay thế toàn bộ bằng [www] listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 user = nginx group = nginx pm = ondemand pm.max_children = 2 ; default: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 pm.start_servers = 20 pm.min_spare_servers = 1 pm.max_spare_servers = 5 pm.max_requests... http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers 4 Mở port Mở file /etc/sysconfig/iptables thêm vào rule sau -A INPUT -m state state NEW -p tcp dport 1109 -j ACCEPT - Khởi động lại iptables service iptables restart - Khởi động lại nginx service nginx restart - Truy cập theo địa chỉ http://domain.com:1109 hoặc http://ip-server:2313 BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 14 Q V Cài đặt vsftpd 1 Cài đặt yum -y install vsftpd... Cài đặt Xcache Chạy lần lượt các lệnh sau yum enablerepo=remi -y install xcache xcache-admin Nếu dùng php 5.6 thì chạy lệnh sau yum enablerepo=remi,remi-php56 -y install xcache xcache-admin service nginx restart service php-fpm restart VII Cài đặt csf 1 Cài các lib cần thiết Yum -y install perl-libwww-perl BLOG HACKING & SECURITY: QUYLEVHB.BLOGSPOT.COM Page 16 Q 2 Cài đặt csf cd /tmp wget http://www.configserver.com/free/csf.tgz

Ngày đăng: 04/04/2015, 18:40

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan