- vừa được xem lúc

Cấu hình domain Virtual Host cho Apache trên docker centos 7

0 0 4

Người đăng: Lập trình đơn giản

Theo Viblo Asia

Hướng dẫn setup docker lên centos 7 xem ở đây:

https://viblo.asia/p/setup-docker-len-centos-7-va-dung-docker-compose-tao-hello-world-voi-apache-GyZJZ3qZLjm

Bước 1: Thêm domain vào file hosts ở máy host VMware,máy guest đã setup centos 7

Copy file hosts ra folder khác ở folder C:\Windows\System32\drivers\etc\hosts

Bước 2:Thêm vào domain cho ip máy guest

Xem ip trong máy guest dùng lệnh

ip a

image.png Update vào file host domain

192.168.64.128 docker.local

sau khi update thì tiến hành copy lại vào folder C:\Windows\System32\drivers\etc\

Bước 3 : Tạo VirtualHost

Copy file httpd.conf ở link sau vào folder /home/hello-apache: https://gist.github.com/thaiviethai99/8d123f43d27152e79d278e68229c153d

File httpd.conf đã mở mod rewrite và thêm load file** docker_local.conf**

Các bạn có thể dùng lệnh sau để copy file từ container to host để update setting theo ý mình

docker cp containerid:/usr/local/apache2/conf/httpd.conf /home

Trong folder /home/hello-apache/ tạo file docker_local.conf với content:

<VirtualHost *:80> ServerAdmin your.email@gmail.com ServerName docker.local ServerAlias www.docker.local DocumentRoot /usr/local/apache2/htdocs/test <Directory /usr/local/apache2/htdocs/test> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /usr/local/apache2/htdocs/error.log CustomLog /usr/local/apache2/htdocs/access.log combined <IfModule mod_dir.c> DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm </IfModule>
</VirtualHost>

Bước 4 : Tạo folder test ở folder cha /home/hello-apache Tạo file test/test.html với nội dung:

test

Update lại file docker-compose.yaml trong folder /home/hello-apache

version: "3.8" services: web: image: httpd:latest # restart: always container_name: demo1 volumes: - /home/hello-apache/test:/usr/local/apache2/htdocs/test - /home/hello-apache/httpd.conf:/usr/local/apache2/conf/httpd.conf - /home/hello-apache/docker_local.conf:/usr/local/apache2/conf/extra/docker_local.conf ports: - "80:80"

Bước 5:Test

Xem containerid đang chạy dùng lệnh

docker ps -a

image.png

Tắt container đang chạy

docker compose down

Tiến hành run container

docker compose up -d

Mở browser và gõ domain http://docker.local/test.html

Kết quả: image.png

Link github:https://github.com/thaiviethai99/virtual-host-docker

Bình luận

Bài viết tương tự

- vừa được xem lúc

Building a Microservice Architecture with Kafka: An E-commerce Example

Hello everyone! In this post, I'm going to walk you through implementing a microservice architecture using .NET 8 and Kafka, a powerful message broker.

0 0 3