a2enmod/a2dismod

วิธีเรียกใช้

# a2enmod <MODULENAME>
# a2dismod <MODULENAME>
รายละเอียดของ module มีดังนี้

  • autoindex ดูไฟล์ในไดเรกทอรี่
  • userdir public_html ของผู้ใช้
  • rewrite การทำ rewrite คือแปลงรูปของ url แบบต่าง ๆ
  • proxy การทำ Redirect ไปยังเครื่องอื่น ตัวอย่างการติดตั้ง
  • cband จำกัดแบนด์วิดธ์ ทำได้หลายอย่าง ยกตัวอย่างแค่อย่างเดียว คือจำกัดการใช้งานต่อไอพีให้ความเร็วไม่เกิน 1000kbps คำร้องไม่เกิน 10 ครั้งต่อวินาที และเปิดการใช้งานได้ไม่เกิน 10 ครั้งต่อวินาที
    # vi /etc/apache2/site-enables/example.com
    <VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName www.example.com
        ServerAlias example.com
        <IfModule mod_cband.c>
            CBandExceededSpeed 1000 10 10
        </IfModule>
        ...
    </VirtualHost>
    # /etc/init.d/apache2 force-reload
    

บันทึกการเปิดโมดูลแบบน้อยสุด module-minimal

# a2enmod actions
# a2enmod alias
# a2enmod authz_host
# a2enmod cgi
# a2enmod dir
# a2enmod mime
# a2enmod php5
# a2enmod rewrite
# a2enmod status
# /etc/init.d/apache2 restart

บันทึกการเปิดใช้โมดูลแบบปกติ module-normal

# a2enmod alias
# a2enmod auth_basic
# a2enmod authn_file
# a2enmod authz_default
# a2enmod authz_groupfile
# a2enmod authz_host
# a2enmod authz_user
# a2enmod autoindex
# a2enmod cgi
# a2enmod dir
# a2enmod env
# a2enmod mime
# a2enmod mod_python
# a2enmod negotiation
# a2enmod php5
# a2enmod setenv
# a2enmod status
# /etc/init.d/apache2 restart

php.ini

# vi /etc/php5/apache2/php.ini

  • หน่วยความจำที่ยอมให้สคริปต์รันได้ ของเก่าเป็น 8M drupal แนะนำ 12M เราใช้ 16M กันเหนียว
    memory_limit = 16M ; Maximum amount of memory a script may consume (8MB)
  • ตัวแปรเป็น global อัตโนมัติ อันนี้ก็กันเหนียว ตอนเขียนโค๊ดเรี่ยราดไว้หลายที่ เก่าเป็น Off เราแก้เป็น On
    register_globals = On
  • ขนาดไฟล์ใหญ่สุด ที่ post ได้ อันนี้จำได้แม่น หน้าแตกเพราะเอา Bon Echo เข้าไม่ได้ เก่าเป็น 8M แก้เป็น 20M
    post_max_size = 20M

a2ensite

  1. แก้ไขไฟล์คอนฟิค
    # vi /etc/apache2/sites-available/klainfo.com
    <VirtualHost *:80>
      ServerAdmin webmaster@klainfo.com
      ServerName www.klainfo.com
      DocumentRoot /var/www/www.klainfo.com/
      <Directory />
        Options FollowSymLinks
        AllowOverride All
      </Directory>
      <Directory /var/www/www.thaitux.info/>
        Options Indexes FollowSymLinks MultiViews
        DirectoryIndex index.html index.php
        AllowOverride All
        Order allow,deny
        allow from all
      </Directory>
    
      ErrorLog /var/log/apache2/error.log
    
      LogLevel warn
    
      CustomLog /var/log/apache2/access.log combined
      ServerSignature On
    </VirtualHost>
    
  2. เปิดใช้งานเวบไซต์ด้วยคำสั่ง
    # a2ensite www.klainfo.com
    # /etc/init.d/apache2 restart

apache2-ssl

  1. ติดตั้ง apache2 กับ ssl
    # aptitude install apache2 openssl
  2. เปิดใช้โมดูล ssl
    # a2enmod ssl
  3. แก้ให้ apache2 ใช้พอร์ต https คือ 443
    # vi /etc/apache2/ports.conf
    NameVirtualHost *:80
    Listen 80
    <IfModule mod_ssl.c>
       # SSL name based virtual hosts are not yet supported, therefore no
       # NameVirtualHost statement here
       Listen 443
    </IfModule>
  4. etch รุ่นล่าสุด ชุดคำสั่งสร้างกุญแจของ apache2 ชื่อ apache2-ssl-certificate หายไปแล้ว ต้องสั่งเองทีละขั้น
    # export RANDFILE=/dev/random
    # mkdir -p /etc/apache2/ssl
    # openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem
    
    กรอกข้อมูลตามปกติ
    ...
    Country Name (2 letter code) [AU]: <<<--- TH
    State or Province Name (full name) [Some-State]: <<<--- Bangkok
    Locality Name (eg, city) []: <<<--- Bangkok
    Organization Name (eg, company) [Internet Widgits Pty Ltd]: <<<--- Example Co.,Ltd.
    Organizational Unit Name (eg, section) []: <<<--- computer
    Common Name (eg, YOUR name) []: <<<--- webmaster
    Email Address []: <<<--- webmaster@example.com
  5. ป้องกันกุญแจ
    # chmod 600 /etc/apache2/ssl/apache.pem
  6. สร้างไฟล์ไซต์ ssl สมมุติชื่อไฟล์ว่า example-ssl โดยเอาโครงมาจากไฟล์ default
    # cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example-ssl
  7. ปรับแก้
    # vi /etc/apache2/sites-available/example-ssl
    
    NameVirtualHost *:443
    <VirtualHost *:443>
    
    ...
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.pem
        SSLProtocol all
        SSLCipherSuite HIGH:MEDIUM
    
    </VirtualHost>
    
    (ตรงนี้ สามารถเปลี่ยนไดเรกทอรี่ของ ssl ไปยังจุดใดก็ได้ ตามที่เราต้องการ
    เช่น ถ้าใช้ svn ไดเรกทอรี่จะเป็น /var/lib/svn/)
  8. สั่งเปิดใช้ไซต์ที่สร้างขึ้น
    # a2ensite example-ssl
  9. สั่งเริ่ม apache2 ใหม่
    # /etc/init.d/apache2 restart
 
ubuntu_apache2.txt · Last modified: 2010/02/03 22:37 by klainfo · [Old revisions]
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki