เพิ่มความปลอดภัยใหักับ Apache Web Server ด้วย OpenSSL (https)
บ่อยครั้งที่เราเห็นเว็บไซต์ต่างๆ ที่การพิมพ์ URL ขึ้นต้นด้วย https:// ซึ่งเป็นการเสริมความปลอดภัยในการใช้งานเว็บไซต์นั่นเอง โดยปกติเว็บไซต์เหล่านี้จะมีการเข้ารหัสการเชื่อมต่อเอาไว้ เราจะพบเจอบ่อยกับเว็บไซต์จำพวก ธนาคาร , อีเมล หรือเว็บไซต์ต่างๆ ที่ต้องการความปลอดภัยในการส่งข้อมูลนั่นเอง ในวันนี้เราจะมารู้วิธีการติดตั้งกันนะครับ ในตัวอย่างจะเป็นการใช้ Linux Fedora , CentOS , RedHat ครับ
ก่อนอื่นให้ทำการตรวจสอบก่อนว่า ได้มีการติดตั้ง OpenSSL โมดูลที่ใช้งานร่วมกับ Apache หรือยัง ซึ่งโมดูลนั้นมีชื่อว่า mod_ssl ดังนี้
# rpm -qa | grep ssl
ขั้นตอนการปรับแต่ง Apache กับ OpenSSL
ขั้นตอนที่ 1
สร้าง RSA คีย์สำหรับ Apache
[root@netserv ssl]# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
..++++++ ………………………………………..++++++
e is 65537 (0×10001)
Enter pass phrase for server.key:
Verifying – Enter pass phrase for server.key:
[root@netserv ~]#
ขั้นตอนที่ 2
นำคีย์ที่ได้จากขั้นตอนแรก มาสร้าง CSR ไฟล์ ซึ่งปกติจะส่งไปยังหน่วยงานที่รับรอง CA (Certificate Authority)
[root@netserv ssl]# openssl req -new -x509 -days 365 -key server.key -out server.crt
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [GB]:TH
State or Province Name (full name) [Berkshire]:Khon Kaen
Locality Name (eg, city) [Newbury]:Khon Kaen
Organization Name (eg, company) [My Company Ltd]:Khon Kaen University
Organizational Unit Name (eg, section) []:E-Saan Software Park
Common Name (eg, your name or your server’s hostname) []:www.linux-server-1.com
Email Address []:chatpong@gmail.comPlease enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@netserv ~]#
ขั้นตอนที่ 3
สร้างไดเรคเทอรีขึ้นมาเพื่อเก็บ SSL Key ที่สร้างขึ้นมา แล้วย้ายไฟล์ server.crt และ server.key มาไว้ภายใต้ไดเรคเทอรีนี้
[root@netserv ~]# mkdir /etc/httpd/ssl
ขั้นตอนที่ 4
แก้ไขไฟล์ /etc/httpd/conf.d/ssl.conf เพื่อชี้ไปยังตำแหน่งของ SSL Key ที่สร้างขึ้นมา
จาก
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
เป็น
SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key
ขั้นตอนที่ 5
รีสตาร์ท apache เซอร์วิส ซึ่งระหว่างการสตาร์ท SSL จะมี Pass Phase ให้ใส่ด้วย ดังนี้
[root@netserv ssl]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: Apache/2.2.3 mod_ssl/2.2.3 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server localhost:443 (RSA)
Enter pass phrase:
OK: Pass Phrase Dialog successful. [ OK ]
[root@netserv ssl]#
ขั้นตอนที่ 6
ลองเรียกไปที่ https://ไอพีเซิร์ฟเวอร์ เพื่อทำการทดสอบ ก็จะสามารถใช้งานได้ครับ
ก่อนอื่นให้ทำการตรวจสอบก่อนว่า ได้มีการติดตั้ง OpenSSL โมดูลที่ใช้งานร่วมกับ Apache หรือยัง ซึ่งโมดูลนั้นมีชื่อว่า mod_ssl ดังนี้













แจ๋วมาเลยครับ
นายนี่เก่งจริงๆ