Home » Categories » VPS » VPS Linux |
Add thêm website trên VPS Apache CentOS |
Article Number: 17 | Rating: Unrated | Last Updated: Fri, Feb 26, 2016 at 11:12 PM
|
Tương tự như bài viết hướng dẫn add thêm website chạy trên VPS nginx CentOS, hôm nay mình sẽ hướng dẫn các bạn cách thực hiện trên webserver Apache. Giới thiệu Virtual Hosts Virtual Hosts được sử dụng để giúp cho một VPS có thể chạy được nhiều website khác nhau. Các bước add thêm website trên VPS Apache chạy CentOS bằng Virtual Hosts như sau: Chuẩn bị serverĐã cài đặt sẵn webserver Apache trên CentOS, có thể tham khảo bài viết cài đặt LAMP trên CentOS Tạo thư mục chứa websiteVí dụ mình sẽ tạo thư mục ở folder /var/www nhé sudo mkdir -p /var/www/example.com/public_html Chú ý thay example.com bằng domain của bạn. Gán quyềnĐảm bảo cho website hoạt động bình thường sudo chown -R apache:apache /var/www/example.com/public_html Ngoài ra chmod 755 để đảm bảo mọi người có thể xem được website của bạn sudo chmod 755 /var/www Cài đặt Virtual HostsMình sẽ chỉnh sửa file cấu hình mặc định của Apache sudo nano /etc/httpd/conf/httpd.conf Thêm đoạn sau vào cuối file: NameVirtualHost *:80 # # NOTE: NameVirtualHost cannot be used without a port specifier # (e.g. :80) if mod_ssl is being used, due to the nature of the # SSL protocol. # # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. # <VirtualHost *:80> ServerAdmin webmaster@example.com DocumentRoot /var/www/example.com/public_html ServerName www.example.com ServerAlias example.com ErrorLog /var/www/example.com/error.log CustomLog /var/www/example.com/requests.log common </VirtualHost> Bạn cần chú ý các dòng NameVirtualHost, Virtual Host, Document Root, and Server Name để sửa lại cho phù hợp. Lưu lại và thoát. Khởi động lại ApacheDừng tất cả tiến trình Apache sudo apachectl -k stop Khởi động Apache sudo /etc/init.d/httpd start Test thử domainGiờ mình sẽ tạo thử file index.html để test thử domain example.com có hoạt động đúng không nhé. sudo nano /var/www/example.com/public_html/index.html Thêm đoạn code html vào file <html> <head> <title>www.example.com</title> </head> <body> <h1>Success: You Have Set Up a Virtual Host</h1> </body> </html> Lưu và thoát. Bây giờ bạn hãy test thử với link http://example.com, nếu kết quả hiện ra như bên dưới là thành công. Cài đặt thêm Virtual HostsĐể add thêm nhiều website nữa, bạn có thể lặp đi lặp lại bước. Cấu trúc file config của Apache lúc nãy sẽ tương tự như sau: <VirtualHost *:80> ServerAdmin webmaster@example.com DocumentRoot /var/www/example.com/public_html ServerName www.example.com ServerAlias example.com ErrorLog /etc/var/www/example.com/error.log CustomLog /var/www/example.com/requests.log common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@example.org DocumentRoot /var/www/example.org/public_html ServerName www.example.org ServerAlias example.org ErrorLog /var/www/example.org/error.log CustomLog /var/www/example.org/requests.log common </VirtualHost> Khởi động lại Apache là tất cả các website sẽ hoạt động. |
Attachments
There are no attachments for this article.
|
Comments There are no comments for this article. Be the first to post a comment. |
Hướng dẫn cài đặt chứng chỉ SSL (https) với Let’s Encrypt trên VPS/Server sử dụng DirectAdmin
Xem 3095 - Đăng ngày Tue, Apr 7, 2020
Hướng dẫn cài đặt LAMP (Linux, Apache, MySQL, PHP) trên CentOS 6
Xem 1034 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn kích hoạt Apache mod_rewrite trên CentOS
Xem 2379 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn Tạo DKIM tên miền trên Zimbra Mail Server
Xem 872 - Đăng ngày Fri, Apr 17, 2020
Thủ thuật tối ưu LAMP server qua htaccess
Xem 691 - Đăng ngày Fri, Feb 26, 2016
Cài đặt FTP Server đơn giản trên CentOS với ProFTPD
Xem 2752 - Đăng ngày Sat, Feb 27, 2016
Cài đặt và bảo mật phpMyAdmin trên CentOS
Xem 1496 - Đăng ngày Fri, Feb 26, 2016
Kích hoạt thư viện hỗ trợ hình ảnh GD trên CentOS
Xem 1045 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn cài đặt LEMP (Linux, Nginx, MySQL, PHP) trên Ubuntu 12.04
Xem 1082 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn cài đặt và bảo mật phpMyAdmin trên Ubuntu 12.04
Xem 1271 - Đăng ngày Fri, Feb 26, 2016
|