Hiển thị các bài đăng có nhãn Thiết Kế Web. Hiển thị tất cả bài đăng

Thứ Sáu, 4 tháng 11, 2022

thumbnail

WP Fastest Cache Settings 2022 (Step By Step Tutorial) 💯 *New Settings*

 WP Fastest Cache là một plugin bộ nhớ cache miễn phí dễ cài đặt. Tuy nhiên, tác giả đã không thực hiện một công việc xuất sắc trong việc nâng cấp plugin cho sức sống thiết yếu của web. Thiếu các gợi ý tài nguyên trình duyệt (tải trước, chuẩn bị trước, kết nối trước), độ trễ JavaScript, loại bỏ CSS không cần thiết, thiếu kích thước hình ảnh, kiểm soát ợ nóng, v.v. (WP Rocket, LiteSpeed ​​Cache và SG Optimizer là một số ít). Nếu bạn muốn có những tính năng tốc độ này, bạn sẽ phải cài đặt một số plugin bổ sung. (Nhận chủ đề WordPress Blazing Fast Newspaper với chi phí thấp:

WP Fastest Cache

Hướng dẫn cài đặt WP Fastest Cache qua video

Thứ Tư, 12 tháng 1, 2022

Thứ Ba, 21 tháng 12, 2021

thumbnail

VirtualHost Examples

 

Running several name-based web sites on a single IP address.

Your server has multiple hostnames that resolve to a single address, and you want to respond differently for www.example.com and www.example.org.

Note

Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.

# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
    DocumentRoot "/www/example1"
    ServerName www.example.com

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/www/example2"
    ServerName www.example.org

    # Other directives here
</VirtualHost>

The asterisks match all addresses, so the main server serves no requests. Due to the fact that the virtual host with ServerName www.example.com is first in the configuration file, it has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first <VirtualHost>.

The above configuration is what you will want to use in almost all name-based virtual hosting situations. The only thing that this configuration will not work for, in fact, is when you are serving different content based on differing IP addresses or ports.

Note

You may replace * with a specific IP address on the system. Such virtual hosts will only be used for HTTP requests received on connection to the specified IP address.

However, it is additionally useful to use * on systems where the IP address is not predictable - for example if you have a dynamic IP address with your ISP, and you are using some variety of dynamic DNS solution. Since * matches any IP address, this configuration would work without changes whenever your IP address changes.

top

Name-based hosts on more than one IP address.

Note

Any of the techniques discussed here can be extended to any number of IP addresses.

The server has two IP addresses. On one (172.20.30.40), we will serve the "main" server, server.example.com and on the other (172.20.30.50), we will serve two or more virtual hosts.

Listen 80

# This is the "main" server running on 172.20.30.40
ServerName server.example.com
DocumentRoot "/www/mainserver"

<VirtualHost 172.20.30.50>
    DocumentRoot "/www/example1"
    ServerName www.example.com

    # Other directives here ...
</VirtualHost>

<VirtualHost 172.20.30.50>
    DocumentRoot "/www/example2"
    ServerName www.example.org

    # Other directives here ...
</VirtualHost>

Any request to an address other than 172.20.30.50 will be served from the main server. A request to 172.20.30.50 with an unknown hostname, or no Host: header, will be served from www.example.com.

top

Serving the same content on different IP addresses (such as an internal and external address).

The server machine has two IP addresses (192.168.1.1 and 172.20.30.40). The machine is sitting between an internal (intranet) network and an external (internet) network. Outside of the network, the name server.example.com resolves to the external address (172.20.30.40), but inside the network, that same name resolves to the internal address (192.168.1.1).

The server can be made to respond to internal and external requests with the same content, with just one <VirtualHost> section.

<VirtualHost 192.168.1.1 172.20.30.40>
    DocumentRoot "/www/server1"
    ServerName server.example.com
    ServerAlias server
</VirtualHost>

Now requests from both networks will be served from the same <VirtualHost>.

Note:

On the internal network, one can just use the name server rather than the fully qualified host name server.example.com.

Note also that, in the above example, you can replace the list of IP addresses with *, which will cause the server to respond the same on all addresses.

top

Running different sites on different ports.

You have multiple domains going to the same IP and also want to serve multiple ports. The example below illustrates that the name-matching takes place after the best matching IP address and port combination is determined.

Listen 80
Listen 8080

<VirtualHost 172.20.30.40:80>
    ServerName www.example.com
    DocumentRoot "/www/domain-80"
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
    ServerName www.example.com
    DocumentRoot "/www/domain-8080"
</VirtualHost>

<VirtualHost 172.20.30.40:80>
    ServerName www.example.org
    DocumentRoot "/www/otherdomain-80"
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
    ServerName www.example.org
    DocumentRoot "/www/otherdomain-8080"
</VirtualHost>
top

IP-based virtual hosting

The server has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the names www.example.com and www.example.org respectively.

Listen 80

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/example1"
    ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.50>
    DocumentRoot "/www/example2"
    ServerName www.example.org
</VirtualHost>

Requests for any address not specified in one of the <VirtualHost> directives (such as localhost, for example) will go to the main server, if there is one.

top

Mixed port-based and ip-based virtual hosts

The server machine has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the names www.example.com and www.example.org respectively. In each case, we want to run hosts on ports 80 and 8080.

Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

<VirtualHost 172.20.30.40:80>
    DocumentRoot "/www/example1-80"
    ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
    DocumentRoot "/www/example1-8080"
    ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.50:80>
    DocumentRoot "/www/example2-80"
    ServerName www.example.org
</VirtualHost>

<VirtualHost 172.20.30.50:8080>
    DocumentRoot "/www/example2-8080"
    ServerName www.example.org
</VirtualHost>
top

Mixed name-based and IP-based vhosts

Any address mentioned in the argument to a virtualhost that never appears in another virtual host is a strictly IP-based virtual host.

Listen 80
<VirtualHost 172.20.30.40>
    DocumentRoot "/www/example1"
    ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/example2"
    ServerName www.example.org
</VirtualHost>

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/example3"
    ServerName www.example.net
</VirtualHost>

# IP-based
<VirtualHost 172.20.30.50>
    DocumentRoot "/www/example4"
    ServerName www.example.edu
</VirtualHost>

<VirtualHost 172.20.30.60>
    DocumentRoot "/www/example5"
    ServerName www.example.gov
</VirtualHost>
top

Using Virtual_host and mod_proxy together

The following example allows a front-end machine to proxy a virtual host through to a server running on another machine. In the example, a virtual host of the same name is configured on a machine at 192.168.111.2. The ProxyPreserveHost On directive is used so that the desired hostname is passed through, in case we are proxying multiple hostnames to a single machine.

<VirtualHost *:*>
    ProxyPreserveHost On
    ProxyPass        "/" "http://192.168.111.2/"
    ProxyPassReverse "/" "http://192.168.111.2/"
    ServerName hostname.example.com
</VirtualHost>
top

Using _default_ vhosts

_default_ vhosts for all ports

Catching every request to any unspecified IP address and port, i.e., an address/port combination that is not used for any other virtual host.

<VirtualHost _default_:*>
    DocumentRoot "/www/default"
</VirtualHost>

Using such a default vhost with a wildcard port effectively prevents any request going to the main server.

A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or no Host: header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file).

You can use AliasMatch or RewriteRule to rewrite any request to a single information page (or script).

_default_ vhosts for different ports

Same as setup 1, but the server listens on several ports and we want to use a second _default_ vhost for port 80.

<VirtualHost _default_:80>
    DocumentRoot "/www/default80"
    # ...
</VirtualHost>

<VirtualHost _default_:*>
    DocumentRoot "/www/default"
    # ...
</VirtualHost>

The default vhost for port 80 (which must appear before any default vhost with a wildcard port) catches all requests that were sent to an unspecified IP address. The main server is never used to serve a request.

_default_ vhosts for one port

We want to have a default vhost for port 80, but no other default vhosts.

<VirtualHost _default_:80>
    DocumentRoot "/www/default"
...
</VirtualHost>

A request to an unspecified address on port 80 is served from the default vhost. Any other request to an unspecified address and port is served from the main server.

Any use of * in a virtual host declaration will have higher precedence than _default_.

top

Migrating a name-based vhost to an IP-based vhost

The name-based vhost with the hostname www.example.org (from our name-based example, setup 2) should get its own IP address. To avoid problems with name servers or proxies who cached the old IP address for the name-based vhost we want to provide both variants during a migration phase.

The solution is easy, because we can simply add the new IP address (172.20.30.50) to the VirtualHost directive.

Listen 80
ServerName www.example.com
DocumentRoot "/www/example1"

<VirtualHost 172.20.30.40 172.20.30.50>
    DocumentRoot "/www/example2"
    ServerName www.example.org
    # ...
</VirtualHost>

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/example3"
    ServerName www.example.net
    ServerAlias *.example.net
    # ...
</VirtualHost>

The vhost can now be accessed through the new address (as an IP-based vhost) and through the old address (as a name-based vhost).

top

Using the ServerPath directive

We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the correct Host: header. Old HTTP/1.0 clients do not send such a header and Apache has no clue what vhost the client tried to reach (and serves the request from the primary vhost). To provide as much backward compatibility as possible we create a primary vhost which returns a single page containing links with an URL prefix to the name-based virtual hosts.

<VirtualHost 172.20.30.40>
    # primary vhost
    DocumentRoot "/www/subdomain"
    RewriteEngine On
    RewriteRule "." "/www/subdomain/index.html"
    # ...
</VirtualHost>

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/subdomain/sub1"
    ServerName www.sub1.domain.tld
    ServerPath "/sub1/"
    RewriteEngine On
    RewriteRule "^(/sub1/.*)" "/www/subdomain$1"
    # ...
</VirtualHost>

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/subdomain/sub2"
    ServerName www.sub2.domain.tld
    ServerPath "/sub2/"
    RewriteEngine On
    RewriteRule "^(/sub2/.*)" "/www/subdomain$1"
    # ...
</VirtualHost>

Due to the ServerPath directive a request to the URL http://www.sub1.domain.tld/sub1/ is always served from the sub1-vhost.
A request to the URL http://www.sub1.domain.tld/ is only served from the sub1-vhost if the client sent a correct Host: header. If no Host: header is sent the client gets the information page from the primary host.

Please note that there is one oddity: A request to http://www.sub2.domain.tld/sub1/ is also served from the sub1-vhost if the client sent no Host: header.

The RewriteRule directives are used to make sure that a client which sent a correct Host: header can use both URL variants, i.e., with or without URL prefix.

Thứ Ba, 7 tháng 9, 2021

thumbnail

Hướng dẫn xử lý mã độc website WordPress triệt để

 Malware (mã độc) là khái niệm được nhắc đến rất nhiều trong thiết kế web hoặc trong quá trình sử dụng web, các thiết bị công nghệ. Đặc biệt, tỷ lệ website WordPress bị nhiễm Malware khá cao. Và chủ đề này được rất nhiều bạn sử dụng WordPress quan tâm.

Vậy cần phải làm gì để xử lý mã độc khi website WordPress bị nhiễm? Bài viết này tôi sẽ hướng dẫn các bạn từng bước xử lý.



Dấu hiệu nhận biết website bị nhiễm mã độc

  • Website bị chuyển hướng (Redirect) sang những website khác. Có nhiều trường hợp chỉ chuyển hướng trên thiết bị di động hoặc truy cập website qua các bộ máy tìm kiếm (Vào trực tiếp sẽ không chuyển hướng)
  • Website bị chèn tự động các liên kết ngoài (Thường ở header hoặc footer)
  • Website bị chèn tự động các bài viết lạ (Thường trong nội dung sẽ có liên kết ngoài)
  • Tự động thêm các thành viên lạ (Thường là tên tiếng anh, hoặc tên không rõ ràng)
  • Website bị mất nội dung (Không có tác động từ phía quản trị viên)
  • Các bài viết bị chèn link ngoài hoặc iframe
  • Trong source code xuất hiện nhiều file lạ
  • Trong các file php, js tự động chèn các đoạn code lạ
  • Tự động cài đặt các themes, plugins mới
  • Bị xoá file hệ thống, plugin, themes,…
  • Bị xoá nội dung file và thay thế bằng code lạ

Các bước cần chuẩn bị trước khi xử lý mã độc

  • Đổi Hosting/VPS: Tiềm ẩn nhất sau khi website bị nhiễm Malware chính là hosting, vps của bạn. Đừng tiếc tiền, hãy đổi qua hosting hoặc VPS khác (Có thể nhờ nhà cung cấp tạo hosting khác hoặc rebuild VPS)
  • Không chạy website khi đang xử lý mã độc: Nếu bạn vừa chạy website và xử lý mã độc không khác nào “nước đổ lá khoai”. Vì khi bạn chạy website mà chưa được xử lý mã độc triệt để thì đó chính là cách để lây lan nhanh hơn

Quy trình thực hiện

Bước 01: Tải toàn bộ source code và database về máy tính

Trong toàn bộ quy trình xử lý mã độc, bạn hãy làm việc trên máy tính (Tránh làm việc trên hosting, VPS). Sau đó, hãy cài đặt trên localhost (xampp, wamp,…) nhưng không chạy website.

Bước 02: Kiểm tra database

Sau khi import database vào localhost, hãy truy cập vào phpmyadmin và kiểm tra bảng wp_options xem 2 dòng siteurl và home có đúng địa chỉ website của bạn không? Nếu không đúng hãy sửa lại.

Tiếp theo, sử dụng tính năng tìm kiếm tất cả bảng trong phpmyadmin. Bạn hãy tìm lần lượt các từ khoá: %shell%, %base64%, %eval%, %<script>%.

Nếu phát hiện ở bảng nào? Hãy loại bỏ chúng ra khỏi database.

Lưu ý: Trước khi loại bỏ chúng, cần kiểm tra kỹ tránh xoá nhầm

Bước 03: Thay mã nguồn WordPress

  • Bạn hãy lên website wordpress.org và download mã nguồn WordPress phiên bản mới nhất về máy tính => giải nén => xoá thư mục “wp-content”
  • Mở source code hiện tại của bạn => Xoá toàn bộ mã nguồn, chỉ giữ lại thư mục “wp-content”, file “wp-config.php”, “.htaccess” (Nếu có)
  • Sao chép mã nguồn WordPress mới vào source code hiện tại của bạn
  • Mở file wp-config.php, nếu thấy code lạ trong file này hãy loại bỏ đoạn code đó

Bước 04: Thay thế plugin đã cài đặt

Đầu tiên, hãy xoá các plugin không liên quan đến website (Có thể do malware tự động cài)

Trong các plugin bạn đã cài đặt có thể có những plugin trả phí, nếu là plugin trả phí bạn chỉ cần giải nén và copy vào thư mục wp-content/plugins

Lưu ý: Nhớ xoá folder cũ, không được ghi đè

Với các plugin miễn phí trên wordpress.org, bạn dựa vào tên folder plugin để download.

Cấu trúc như sauhttps://wordpress.org/plugins/ten_folder

Ví dụ: Plugin có folder wordpress-seo thì bạn chỉ cần vào link sau: https://wordpress.org/plugins/wordpress-seo

Hãy luôn nhớ rằng: Không được ghi đè, phải xoá folder plugin cũ.

Nếu trên website đã sử dụng các plugin NULL, hãy xoá nó ngay và mua các plugin thay thế (Hoặc tìm plugin khác để thay thế)

Bước 05: Kiểm tra themes

Đầu tiên, hãy xoá các theme không liên quan (Cẩn thận xoá nhầm)

Tiếp theo, mở các file php, js và xoá các đoạn code lạ: Thường là code mã hoá, hoặc hàm eval

Các thư viện, plugin của jQuery bạn có thể thay mới (Vì khó kiểm tra). Ví dụ: jquery.min.js, bootstrap.min.js, owl-carouse.min.js,…

Lưu ý: Nhớ kiểm tra phiên bản các thư viện, plugin đó để tránh website bị lỗi

Tiếp theo, kiểm tra trong theme và các folder trong theme có file nào lạ không? Nếu có hãy loại bỏ chúng. Đừng chủ quan những thư mục liên quan đến fontscssimages,…

Bước 06: Kiểm tra thư mục uploads, languages, upgrade

– Trong thư mục uploads: Hãy loại bỏ tất cả những file không phải là định dạng ảnh, video, file tài liệu do bạn upload lên

– Trong thư mục languages: Hãy loại bỏ tất cả những file không phải là định dạng .mo, .po

– Trong thư mục upgrade: Hãy loại bỏ tất cả các file lạ (Thường là .php)

Bước 07: Kiểm tra thư mục wp-content

Trong thư mục có thể sẽ có những file lạ, bạn cần loại bỏ chúng. Kể cả file index.php của thư mục wp-content, nhiều khi malware cũng chèn vào file đó. Bạn cần phải xoá code lạ trong file đó nhưng đừng xoá file đó.

Bước 08: Xoá các bài viết, trang, users

Bạn đăng nhập vào trang quản trị và thực hiện kiểm và xoá các bài viết, trang, users tự sinh ra. Bạn cũng cần kiểm tra các bài viết do bạn viết xem có bị chèn script, frame lạ không? Nếu có, hãy xoá chúng.

Bước 09: Kiểm tra lại bằng plugin Wordfence Security

Không có nghĩa plugin này giúp kiểm tra chính xác, plugin này giúp tham khảo thêm việc kiểm tra mã độc có còn không? Qua quá trình làm việc, tôi đã làm việc với plugin này và thấy nó khá hiệu quả.

Sau khi cài đặt plugin này xong, bạn scan và đợi kết quả báo cáo của plugin. Nếu vẫn còn, bạn hãy rà soát lại xem còn thiếu bước nào không và thực hiện xử lý lại.

Bước 10: Deploy website lên hosting mới và theo dõi

Việc này sẽ mất một thời gian theo dõi, nếu sau khoảng vài ngày đến 1-2 tuần mà không có vấn đề gì, mình nghĩ website của bạn tạm thời đã xử lý xong mã độc.

Các bước thiết lập để bảo vệ website WordPress

  • Đặt mật khẩu quản trị, hosting có độ phức tạp cao
  • Đổi đường link truy cập wp-admin. Tham khảo plugin Protect Your Admin
  • Tránh việc chạy nhiều website trên 1 hosting (Đặc biệt là share hosting)
  • Sử dụng thêm plugin Wordfence Security để bảo vệ và cảnh báo
  • Bật CFS firewall trên Server
  • Cập nhật liên tục WordPress Core và Plugin (Khi có phiên bản mới)
  • TUYỆT ĐỐI: Không sử dụng các plugin, theme NULL
  • Nếu website của bạn có những form tự viết hãy kiểm tra lại code và filter input. Tham khảo link sau: https://developer.wordpress.org/plugins/security/securing-input
  • Cập nhật tin tức về lỗi bảo mật của các plugin, nếu thấy tin xấu mà chưa có bản update, hãy xoá ngay.
  • Có thể thiết lập thêm lớp bảo vệ folder khu vực quản trị bằng .htaccess

KẾT LUẬN

Trên đây, tôi đã chia sẻ ít kinh nghiệm của tôi về việc xử lý mã độc WordPress và cách phòng tránh. Việc website bị nhiễm mã độc đừng chỉ đổ lỗi cho WordPress, Plugin, Themes. Người dùng cũng góp phần lớn khiến website bị nhiễm mã độc. Cho nên hãy để ý để website của mình được an toàn.

Nếu có bất kỳ câu hỏi nào, hãy comment phía dưới bài viết này.

Bài đăng tiêu biểu