29 1 web squid php mysql

8 3 0
29 1  web squid php mysql

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

Thông tin tài liệu

UnixLinuxVN – Bài thực hành linux LPIC02 Linux Basic Course 1 Bài thực hành Web, Squid, php và Mysql Cài đặt web server apache 1 Cấu hình card mạng máy server và client ở chế độ host only và các địa c.

UnixLinuxVN – Bài thực hành linux LPIC02 Bài thực hành Web, Squid, php Mysql Cài đặt web server apache Cấu hình card mạng máy server client chế độ host-only địa sau (chú ý tên card mạng thay đổi tùy hệ thống – giả thiết card mạng dùng ens33): [root@server etc] #ifconfig [root@server etc] #ifconfig ens33 10.0.0.1/24 up [root@client etc] #ifconfig ens33 10.0.0.2/24 up Thử kết nối [root@client etc] # ping 10.0.0.1 Cài đặt dịch vụ web server [root@server etc] #yum -y install httpd Chạy dịch vụ httpd [root@server etc] #service httpd start Hoặc [root@server etc] #systemctl restart httpd Kiểm tra cổng mở server [root@server etc] # netstat –an | grep 80 Vào máy client thử nghiệm trang web Cấu hình web server sử dụng IP based virtual host Cấu hình httpd sau: [root@server etc] # vi /etc/httpd/httpd.cond DocumentRoot /var/www/html/virtualhost1/ DocumentRoot /var/www/html/virtualhost2/ Tạo trang web index.html thư mục /var/html/www/virtualhost1 [root@server etc] # vi /var/html/www/virtualhost1/index.html This is virtual host Tạo trang web index.html thư mục /var/html/www/virtualhost2 [root@server etc] # vi /var/html/www/virtualhost2/index.html This is virtualhost Chạy dịch vụ httpd [root@server etc] #service httpd start Kiểm tra cổng mở server [root@server etc] # netstat –an | grep 80 Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 Vào máy client thử nghiệm trang web [root@client etc] #mozilla http://10.0.0.1 & Vào máy test thử nghiệm trang web [root@test etc] #mozilla http://10.0.0.2 & Cấu hình web server sử dụng Name based virtual host Cấu hình DNS máy server để phân dải hai tên miền sau: (hoặc dùng file host window) virtualhost1.lablinux.com IN A 10.0.0.1 virtualhost2.lablinux.com IN A 10.0.0.1 Cấu hình card mạng máy client máy server tới DNS máy server [root@server etc] #vi /etc/resolv.conf Nameserver 10.0.0.1 [root@client etc] #vi /etc/resolv.conf Nameserver 10.0.0.1 Thử kết nối [root@test etc] # ping virtualhost1.lablinux.com [root@test etc] # ping virtualhost2.lablinux.com Cấu hình httpd sau: [root@server etc] # vi /etc/httpd/conf.d/virtualhost.conf NameVirtualHost 10.0.0.1 #Dịng có với CentOS, Redhat trở xuống ServerAdmin webmaster@lablinux.vn DocumentRoot /var/www/html/virtualhost1 ServerName virtualhost1.lablinux.com ServerAdmin webmaster@lablinux.vn DocumentRoot /var/www/html/virtualhost1 ServerName virtualhost2.lablinux.com Chạy dịch vụ httpd [root@server etc] #service httpd start [root@server etc] #systemctl restart httpd Kiểm tra cổng mở server [root@server etc] # netstat –an | grep 80 Vào máy client thử nghiệm trang web [root@client etc] #mozilla http://virtualhost1.lablinux.com & Vào máy test thử nghiệm trang web [root@test etc] #mozilla http://virtualhost2.lablinux.com & Cấu hình webserver có vùng bị giới hạn truy cập Trong virtualhost1 có vị trí /var/www/html/virtualhost1/safe cần giới hạn truy cập Cấu hình httpd máy server sau: [root@server etc] # vi /etc/httpd/conf.d/virtualhost.conf Khai báo đoạn cấu hình sau phần virtualhost1 Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 Order allow,deny Deny from 10.0.0.2 Allow from all Alias /safe /var/www/safe Tạo trang web vào thư mục /var/www/html/virtualhost1/safe [root@server etc] # mkdir /var/www/html/virtualhost1/safe [root@server safe] # vi index.html This is safe page Chạy lại dịch vụ httpd [root@server etc] #service httpd restart Vào máy client thử nghiệm trang web [root@client etc] #mozilla http://virtualhost1.lablinux.com/safe & Vào máy test thử nghiệm trang web [root@test etc] #mozilla http://virtualhost1.lablinux.com/safe & Cấu hình webserver để địi hỏi chứng thực Cấu hình lại httpd máy server sau: [root@server etc] # vi /etc/httpd/conf.d/virtualhost.conf Khai báo đoạn cấu hình sau phần virtualhost1 AuthType basic AuthName "protected site" AuthUserFile /etc/httpd/conf/safe.passwd Require user ipmac Alias /safe /var/www/safe Tạo file safe.passwd để lưu mật mã user ipmac [root@server etc] # htpasswd -c /etc/httpd/conf/safe.passwd ipmac Chạy dịch vụ httpd [root@server etc] #service httpd restart Hoặc [root@server etc] #systemctl restart httpd Vào máy client thử nghiệm trang web [root@client etc] #mozilla http://virtualhost1.lablinux.com/safe & Tạo trang web với php Cài đặt gói php [root@server etc]# yum -y install php Tạo file index.php thư mục virtualhost1 sau: PHP Test Chạy lại dịch vụ httpd [root@server etc] #service httpd restart Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 Vào máy client thử nghiệm trang web [root@client etc] #mozilla http://10.0.0.1/index.php Tạo trang web https với apache Cài đặt module ssl hỗ trợ tính mã hóa cho web server apache [root@server etc]# yum -y install mod_ssl Kiểm tra nội dung khai báo mặc định cho https [root@server etc]# more /etc/httpd/conf.d/ssl.conf Khai báo cấu hình virtual host cho https [root@server etc]# vi /etc/httpd/conf.d/virtualhost.conf NameVirtualHost 10.0.0.1:443 #khơng cần khai báo dịng với Enterprise linux trở lên ServerName virtualhost1.lablinux.com DocumentRoot /var/www/html/virtualhost1 SSLEngine on SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key Chạy lại dịch vụ httpd [root@server etc] #service httpd restart Hoặc [root@server etc] #systemctl restart httpd Vào máy client thử nghiệm trang web [root@client etc] #mozilla https://virtualhost1.lablinux.com Cấu hình Nginx webserver Cài đặt Nginx webserver [root@server etc] #yum install epel-release [root@server etc] #yum -y install nginx Bật dịch vụ nginx [root@server etc] #systemctl enable nginx [root@server etc] #systemctl disable httpd [root@server etc] #systemctl stop httpd [root@server etc] #systemctl start nginx Cấu hình virtualhost với nginx Tạo file cấu hình virtualhost [root@server etc] #vi /etc/nginx/conf.d/virtualhost.conf server { listen 80; server_name web1.com www.web1.com; location / { root /var/www/html/virtualhost1; } } server { listen 80; server_name web2.com www.web2.com; location / { Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 root /var/www/html/virtualhost2; } } Khởi động lại dịch vụ nginx [root@server etc] #systemctl restart nginx Vào máy client thử nghiệm trang web [root@client etc] #mozilla http:// web1.com/ & Vào máy test thử nghiệm trang web [root@test etc] #mozilla http:// web2.com / & Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 Cài đặt proxy Squid Cài đặt gói squid proxy [root@server etc] #yum -y install squid Enable squid proxy [root@server etc] #systemctl enable squid [root@server etc] #systemctl start squid Kiểm tra squid proxy [root@server etc] #curl -x http://10.0.0.1:3128 -L http://google.com Cấu hình xác thực cho squid proxy Chỉnh sửa file cấu hình proxy sau: [root@server etc]# vi /etc/squid/squid.conf auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd auth_param basic children auth_param basic realm Squid Basic Authentication auth_param basic credentialsttl hours acl auth_users proxy_auth REQUIRED http_access allow auth_users Khởi động lại dịch vụ squid [root@server etc]# systemctl restart squid Truy cập thử từ client hỏi thông tin đăng nhập Cấu hình giới hạn website Tạo file lưu trang web giới hạn sau: [root@server etc] #vi /etc/squid/blocked_sites facebook.com vnexpress.net dantri.com.vn docbao.com.vn unixlinuxvn.com Khai báo giới hạn squid: [root@server etc] #vi /etc/squid/squid.conf acl blocked_sites dstdomain "/etc/squid/blocked_sites" http_access deny blocked_sites Khởi động lại squid proxy: [root@server etc]# systemctl restart squid Từ client truy cập thử site giới hạn nhận thông báo tương tự sau: Customize err page: /usr/share/squid/errors Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 Cấu hình reverse proxy với Nginx webserver Tạo cấu hình virtualhost cho web3 [root@server etc] #vi /etc/nginx/conf.d/virtualhost.conf server { listen 80; server_name web3.com www.web3.com; location / { proxy_pass http://10.0.0.3 } } Khởi động lại dịch vụ nginx [root@server etc] #systemctl restart nginx Vào máy client thử nghiệm trang web [root@client etc] #mozilla http:// web3.com/ & Cấu hình reverse proxy với apache webserver Tạo cấu hình virtualhost cho web3 [root@server etc] #vi /etc/httpd/conf.d/virtualhost.conf ServerName web3.com ServerAlias www.web3.com ProxyPass "/" "http://10.0.0.3" timeout=120 Khởi động lại dịch vụ httpd [root@server etc] #systemctl restart httpd Vào máy client thử nghiệm trang web [root@client etc] #mozilla http:// web3.com/ & Cấu hình reverse proxy load balancing với apache webserver Tạo cấu hình virtualhost cho web3 [root@server etc] #vi /etc/httpd/conf.d/virtualhost.conf ServerName web3.com ServerAlias www.web3.com BalancerMember http://10.0.0.4:80 BalancerMember "http://10.0.0.4:80" ProxyPass "/" "balancer://myload" timeout=120 Khởi động lại dịch vụ httpd [root@server etc] #systemctl restart httpd Vào máy client thử nghiệm trang web [root@client etc] #mozilla http:// web3.com/ & Cấu hình reverse proxy load balancing với nginx webserver Tạo cấu hình virtualhost cho web3 [root@server etc] #vi /etc/nginx/conf.d/virtualhost.conf Linux Basic Course UnixLinuxVN – Bài thực hành linux LPIC02 server { listen 80; server_name web3.com www.web3.com; upstream backend { server 10.0.0.3 weight=5; server 10.0.0.4; } location / { proxy_pass http://backend } } Khởi động lại dịch vụ nginx [root@server etc] #systemctl restart nginx Vào máy client thử nghiệm trang web [root@client etc] #mozilla http:// web3.com/ & Linux Basic Course ... trang web [root@client etc] #mozilla http://virtualhost1.lablinux.com/safe & Tạo trang web với php Cài đặt gói php [root@server etc]# yum -y install php Tạo file index .php thư mục virtualhost1 sau:... NameVirtualHost 10 .0.0 .1 #Dịng có với CentOS, Redhat trở xuống ServerAdmin webmaster@lablinux.vn DocumentRoot /var/www/html/virtualhost1 ServerName virtualhost1.lablinux.com... virtualhost1.lablinux.com IN A 10 .0.0 .1 virtualhost2.lablinux.com IN A 10 .0.0 .1 Cấu hình card mạng máy client máy server tới DNS máy server [root@server etc] #vi /etc/resolv.conf Nameserver 10 .0.0 .1 [root@client

Ngày đăng: 14/12/2022, 10:32

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

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

Tài liệu liên quan