Open Source How-To

You are here: Home > 3. Ubuntu 16.04 Server > การตั้งค่า https สำหรับ Apache2 web server ด้วยไฟล์ SSLCertificate ที่ซื้อ

การตั้งค่า https สำหรับ Apache2 web server ด้วยไฟล์ SSLCertificate ที่ซื้อ

 
 

บันทึกนี้ดูแลโดยวิบูลย์
ปรับปรุงล่าสุดเมื่อ 14-02-2563

ตัวอย่างนี้ผมทดสอบกับ web server opensource.cc.psu.ac.th ครับ โดยสรุปความรู้มาจากหลาย ๆ เว็บเพจ
โดยที่ ubuntu server ที่ใช้งาน เป็น 16.04

1. เข้าทำงานเป็น root
sudo su -

2.เอาไฟล์ SSLCertificate มาเก็บไว้อย่างปลอดภัย (ตัวอย่าง cc.psu.ac.th)
เอาไฟล์ SSLCertificate ที่ซื้อมาไว้ที่ server สมมติที่ไดเรกทอรี /home/mama จากนั้นทำคำสั่ง
สมมติว่าจะวาง certificate files ไว้ที่ /etc/ssl/private/
cd /etc/ssl/private/
unzip /home/mama/star.cc.psu.zip
chmod -R 640 star.cc.psu/

3.สร้างไฟล์ที่จะ start https
สมมติว่าใน /etc/ssl/private/ มี 5 ไฟล์ คือ alphassl.ca-bundle, ccpsu.crt, ccpsu.key, ccpsu.pem, ccpsu.pfx

SSLCertificateFile      /etc/ssl/private/star.cc.psu/ccpsu.crt
SSLCertificateKeyFile   /etc/ssl/private/star.cc.psu/ccpsu.key
SSLCertificateChainFile /etc/ssl/private/star.cc.psu/alphassl.ca-bundle

หรืออีกตัวอย่าง สมมติว่าใน /etc/ssl/private/ มี 3 ไฟล์ คือ intermediate_domain_ca.crt, STAR_psu_ac_th.crt, STAR_psu_ac_th.key

SSLCertificateFile      /etc/ssl/private/STAR_psu_ac_th.crt
SSLCertificateKeyFile   /etc/ssl/private/STAR_psu_ac_th.key
SSLCertificateChainFile /etc/ssl/private/intermediate_domain_ca.crt


สมมติว่าเราจะตั้งชื่อ config file ว่า opensource-ssl.conf (ตั้งชื่ออื่นได้ เช่น ให้ตรงกับชื่อเว็บไซต์ เป็นต้น)
cd /etc/apache2/sites-available/
cp default-ssl.conf opensource-ssl.conf
nano opensource-ssl.conf

ตำแหน่งนี้คือตอนต้นของไฟล์
<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerName opensource.cc.psu.ac.th
                ServerAdmin webmaster@localhost
                DocumentRoot /var/www/
                <Directory /var/www/>
                        Options FollowSymLinks MultiViews
                        AllowOverride None
                        Order allow,deny
                        allow from all
                </Directory>
                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                # error, crit, alert, emerg.
                # It is also possible to configure the loglevel for particular
                # modules, e.g.
                #LogLevel info ssl:warn
                ErrorLog ${APACHE_LOG_DIR}/opensource-ssl_error.log
                CustomLog ${APACHE_LOG_DIR}/opensource-ssl_access.log common
                SSLEngine on
                SSLCertificateFile      /etc/ssl/private/star.cc.psu/ccpsu.crt
                SSLCertificateKeyFile   /etc/ssl/private/star.cc.psu/ccpsu.key
                SSLCertificateChainFile /etc/ssl/private/star.cc.psu/alphassl.ca-bundle
# Do this Line for SSL very secure
Header add Strict-Transport-Security "max-age=15768000;includeSubDomains"
ยังมีบรรทัดอื่น ๆ ไม่เกี่ยว

save ไฟล์

4. enable module ที่ต้องใช้
a2enmod headers
a2enmod ssl

5. ขั้นตอนทำให้ได้ SSL ที่ secure มาก ๆ
nano /etc/apache2/mods-enabled/ssl.conf

SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
SSLHonorCipherOrder on
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCompression off
</IfModule>
ตำแหน่งนี้คือตอนท้ายของไฟล์

Save ไฟล์

6. enable web site ssl ที่สร้างขึ้นใหม่
a2ensite opensource-ssl.conf

7. restart apache2 web server
service apache2 restart

เสร็จแล้ว

หาก error ก็ต้องหาว่า พิมพ์ผิดอะไรบ้าง บางบรรทัดก็ยาวมาก ระวังอย่าให้เกิดการตัดบรรทัด

References:
การแก้ไข Certificate สำหรับ Apache Web Server (Ubuntu 14.04 LTS)
https://sysadmin.psu.ac.th/2015/11/10/certificate-apache-web-server-ubuntu-14-04-lts/
เปลี่ยน Certificate!?
https://sysadmin.psu.ac.th/2014/12/18/เปลี่ยน-certificate/
Byeๆ TLS1.0 TLS1.1
https://sysadmin.psu.ac.th/2020/02/14/bye-tls1-0-tls1-1/

nach oben