1.檢查網絡環境,查看服務器是否可以上網
ifup ens33 打開ens33網卡
ping www.baidu.com
2.Centos 7配置阿里雲yum源和安裝EPEL源
(1)對默認原文件進行備份
#cd /etc/yum.repos.d
#mkdir bak
#mv *.repo bak/
(2)配置阿里雲yum源
#wget http://mirrors.aliyun.com/repo/Centos-7.repo
#yum clean all 清除緩存
#yum makecache 重新生成緩存
(3)安裝epel源
yum install -y epel-release
3、安裝nginx並配置服務
(1)安裝nginx服務
#yum install nginx -y
使用systemctl start nginx 啓動服務
在根目錄下創建data目錄
(2)修改nginx配置文件
#vim /etc/nginx/nginx.conf
在文件最後一個}號前添加:include vhost/*.conf;
(3)域名配置
在/etc/nginx目錄下新建vhost目錄,並在下面新建www.test.conf與www.hr.conf兩個域名配置文件,並作如下編輯。
#vim www.test.conf
server{
listen 192.168.75.131:80;
server_name www.test.com;
location / {
root /data/test;
index index.html;
}
}
#vim www.hr.conf
server{
listen 192.168.75.131:80;
server_name www.hr.com;
location / {
root /data/hr;
index index.html;
}
}
(4)上傳網站文件
將公司網站文件test和hr都放入到/data/目錄下
使用winscp上傳,或者直接拖入虛擬機
(5)配置完成後重啓服務
systemctl restart nginx
(6)關閉防火牆
systemctl status firewalld.service
關閉selinux安全機制:setenforce 0
4.配置基於域名的虛擬主機
域名註冊,在/etc/hosts中追加一行
192.168.75.128 www.test.com www.hr.com
5.網站訪問測試
在瀏覽器分別輸入www.test.com和www.hr.com測試公司是否能夠訪問