Bạn vào file /etc/hosts , thêm 1 cái domain như thế này nhé virtual.host
[1] Bạn tạo 1 file cấu hình virtual.host.conf trong folder /etc/nginx/conf.d
Mình giải thích thêm phần này, nginx sẽ tự động quét tất cả các file có đuôi là conf trong folder này nhé /etc/nginx/conf.d
Thường thì mình sẽ cấu hình mỗi website là 1 file và đặt trong đây /etc/nginx/conf.d
[root@www ~]# vi /etc/nginx/conf.d/virtual.host.conf
# create new
server {
listen 80;
server_name www.virtual.host;
location / {
root /usr/share/nginx/virtual.host;
index index.html index.htm;
}
}
[root@www ~]# mkdir /usr/share/nginx/virtual.host
[root@www ~]# systemctl restart nginx
[2] Tạo một page để test thử nhé
[root@www ~]# vi /usr/share/nginx/virtual.host/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx Virtual Host Test Page
</div>
</body>
</html>
Facebook Social Comments