[Varnish] วิธีบันทึก Client IP บนเครื่อง backend

เราสามารถทำการบันทึก Client IP ทีเครื่อง backend  แทนที่จะให้ปรากฎเป็น IP ของ varnish เช่น 127.0.0.1  สามารถทำได้โดยการ แก้ไขไฟล์ /etc/varnish/default.vcl

sub vcl_recv {
  # Add a unique header containing the client address
  remove req.http.X-Forwarded-For;
  set    req.http.X-Forwarded-For = client.ip;
  # [...]
}

และเพิ่มบรรทัดต่อไปนี้ในไฟล์ /etc/httpd/conf/httpd.conf

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined

และใน VirtualHost directive ให้ใช้ CustomLog ดังตัวอย่างต่อไปนี้

<VirtualHost *:80>
  ServerName www.example.com
  # [...]
  CustomLog /var/log/apache2/www.example.com/access.log varnishcombined
  # [...]
</VirtualHost>

ที่มา: http://varnish-cache.org/wiki/FAQ#HowcanIlogtheclientIPaddressonthebackend

Popularity: 1% [?]

แชร์ไดเรกทอรีระหว่าง Linux กับ Mac OS X

ผมติดตั้ง CentOS linux 5.5 ใน parallels virtual machine แล้วหาทางส่งไฟล์ระหว่างกัน วิธีการหนึ่งที่สามารถทำได้คือผ่าน samba ซึ่งมีขั้นตอนดังนี้ครับ

  1. ติดตั้ง samba ใน linux ด้วยคำสั่ง
    #yum install samba
  2. แก้ไขไฟล์ /etc/samba/smb.conf ให้มีเนื้อหาในส่วนของ [homes] เป็น
    [homes]
    comment = Home Directories
    browseable = yes
    writeable = yes
    read only = yes
  3. สั่งให้ samba ทำงานด้วยคำสั่ง
    #/etc/init.d/smb start
  4. กำหนด password ให้ user  โดย user นั้นจะต้องมีจริงในระบบ (local user)
    # smbpasswd -a username
  5. ที่เครื่อง mac เปิด Finder เลือก Go และ Connect to Server
  6. ป้อน smb://หมายเลข ip ของ linux เช่น
    smb://192.168.1.11

Popularity: 1% [?]

@font-face

@font-face ใน CSS3 จะช่วยให้เราสามารถนำฟ้อนต์ที่เราต้องการไปใช้ในเว็บได้ อย่างไรก็ตามปัจจุบันบราวเซอร์แต่ละชนิดก็รองรับชนิดของฟ้อนต์แตกต่างกัน เช่น IE ต้องการเฉพาะ .eot (Embedded OpenType)  ในขณะที่ Safari, Firefox, Chrome และ Opera รองรับทั้ง .ttf  (TrueType Font ) และ .otf  (OpenType PS) โดยสามารถดูตาราง Browser Supprot for @font-face ได้ที่นี่

อย่างไรก็ตามวันที่ 8 เม.ย. 53 ที่ผ่านมา Microsoft, Mozilla และ Opera ได้ยื่นข้อเสนอมาตรฐานรูปแบบฟ้อนต์ที่ใช้บนเว็บ WOFF (Web Open Font Format) กับ  W3C    ซึ่งคงต้องรออีกพักหนึ่งกว่าที่จะกลายมาเป็นมาตรฐานที่ใช้กันได้ทั่วไป   ดังนั้นในเวลานี้เราก็คงต้องใช้รูปแบบฟ้อนต์ที่บราวเซอร์ในปัจจุบันใช้งานได้ไปก่อน

รูปแบบของการเขียน @font-face มีดังนี้


@font-face {
  font-family: AnyFontName;   /* required */
  src: source;	              /* required */
  font-weight: weight;        /* optional */
  font-style: style;          /* optional */
}

ตัวอย่างรูปแบบการกำหนด source ของ font


@font-face {
     font-family: AnyFontName;
     src: url('../fonts/fontname1.eot');
     src: local('fontname2'),
          url('../fonts/fontname3') format('opentype'),
          url('../fonts/fontname4') format('svg');
}

จากตัวอย่างข้างต้น  เราสามารถตั้งชื่อ  font-family ได้ตามต้องการ  ซึ่งจะมีการเรียกใช้ชื่อฟ้อนต์ที่ตั้งไว้ดังนี้


h3 {
    font-family: AnyFontName, arial, helvetica, sans-serif;
}

ข้อความที่อยู่ระหว่าง <h3> และ </h3> ก็จะถูกแสดงด้วยฟ้อนที่ชื่อ AnyFontName    แต่เนื่องจาก browser รองรับฟอนต์ได้ไม่เหมือนกัน โดยเฉพาะ IE จึงมีผู้ทำการทำสอบว่าจะเขียน @font-face ในรูปแบบใดจึงจะเหมาะสมที่สุด

Useful links:

http://snook.ca/archives/html_and_css/becoming-a-font-embedding-master

http://xmlgraphics.apache.org/batik/tools/font-converter.html

http://www.fontsquirrel.com/fontface/generator

http://code.google.com/p/ttf2eot/

http://webfonts.info/wiki/index.php?title=@font-face_browser_support

Popularity: 1% [?]

MySQL: ย้ายข้อมูลระหว่างฐานข้อมูล

วิธีการง่ายๆ ในการย้ายข้อมูลระหว่าง  database สามารถทำได้ดังนี้

  1. สร้างฐานข้อมูลใหม่ เช่น  new_database
  2. ใช้คำสั่ง mysqldump ดังนี้
    #mysqldump -uroot -p old_database | mysql -uroot -p -D new_database

Popularity: 1% [?]

สิ่งที่ควรทำหลังจาก upgrade MySQL server

หลังจากทำการ upgrade MySQL server ควรจะใช้คำสั่งต่อไปนี้
#mysql_upgrade -uroot -p
และ

#mysqlcheck -uadmin -p --auto-repair --check --optimize --all-databases

เพื่อตรวจสอบว่ามีปัญหาระหว่างการ upgrade หรือไม่ เนื่องจากผมเจอปัญหาที่ดูเหมือนว่าฐานข้อมูลหายไป เมื่อตรวจสอบแล้วก็พบว่าฐานข้อมูลยังอยู่ แต่ถูกเติมข้างหน้าด้วย #mysql50#

If you have databases or tables from a version of MySQL older than 5.1.6 that contain special characters and for which the underlying directory names or file names have not been updated to use the new encoding, the server displays their names with a prefix of #mysql50# in the output from INFORMATION_SCHEMA tables or SHOW statements.

ที่มา http://dev.mysql.com/doc/refman/5.1/en/identifier-mapping.html

Popularity: 1% [?]

Next Page »