Home  >  Article  >  Computer Tutorials  >  Detailed tutorial on Apache optimization and hotlink prevention in Linux system

Detailed tutorial on Apache optimization and hotlink prevention in Linux system

PHPz
PHPzforward
2024-02-20 09:00:04704browse

Detailed tutorial on Apache optimization and hotlink prevention in Linux system

The following is a detailed tutorial on Apache optimization and anti-leeching under Linux system:

  1. Apache performance optimization:

    • Enable compression: Enable Gzip compression in the Apache configuration file to reduce the size of transferred data.

      LoadModule deflate_module modules/mod_deflate.so
      <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
      </IfModule>
    • Adjust KeepAlive settings: Adjust KeepAlive settings in the Apache configuration file to optimize the performance of concurrent connections.

      KeepAlive OnMaxKeepAliveRequests 100KeepAliveTimeout 5
    • Configure cache: Use Apache's cache function to cache static files and reduce the load on the back-end server.

      <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 1 month"</IfModule>
    • Use PHP cache: If you use PHP, you can install and configure a PHP cache to improve performance, such as APC or OpCache.
  2. Anti-leeching settings:

    • Add the following configuration in the Apache configuration file to implement the anti-leeching function:

      <Directory "/path/to/protected/directory">
        Options Indexes FollowSymLinks  AllowOverride All
        Order deny,allow
        Deny from all
        # 允许特定域名或IP访问资源
        Allow from example.com  Allow from 192.168.0.0/24</Directory>

      This will only allow the example.com domain name and the IP address of the 192.168.0.0/24 network segment to access the specified directory. Requests from other sources will be rejected.

  3. HTTPS configuration:

    • Obtain an SSL certificate: Obtain an SSL certificate from a trusted certificate authority, or use a free certificate authority such as Let’s Encrypt to obtain a certificate.
    • Configure Apache: Add the following configuration in the Apache configuration file to enable HTTPS.

      <VirtualHost *:443>
        ServerName example.com  SSLEngine on
        SSLCertificateFile /path/to/certificate.crt  SSLCertificateKeyFile /path/to/private.key  # 其他配置项</VirtualHost>

These are basic tutorials on Apache optimization and hotlink prevention under Linux systems. Depending on actual needs and specific circumstances, you may need to make more configurations and adjustments. Before modifying the Apache configuration file, make sure you have a certain understanding of the configuration syntax and operations, and back up the original configuration file in case unexpected situations occur.

Hope this tutorial is helpful to you. If you have any questions, please feel free to ask.

The above is the detailed content of Detailed tutorial on Apache optimization and hotlink prevention in Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete