当前位置:   article > 正文

虚拟主机搭建网站

虚拟主机搭建网站

1.基于域名www.openlab.com可以访问网站内容为welcome to openlab

关闭selinux和防火墙;创建网页目录,并写入内容;并在linux下的hosts文件内写入域名与本机ip地址的映射

  1. [root@server ~]# setenforce 0
  2. setenforce: SELinux is disabled
  3. [root@server ~]# systemctl stop firewalld
  4. [root@server ~]# yum install httpd -y
  5. [root@server ~]# mkdir -p /www/openlab
  6. [root@server ~]# ehco 'welcom to openlab' > /www/openlab/index.html
  7. [root@server ~]# vim /etc/hosts

 编辑httpd的主配置文件,并写入虚拟主机内容,重启服务

  1. [root@server conf]# vim /etc/httpd/conf/httpd.conf
  2. <VirtualHost 192.168.95.131>
  3. DocumentRoot /www/openlab
  4. ServerName "www.openlab.com"
  5. <Directory /www/openlab>
  6. AllowOverride None
  7. require all granted
  8. </Directory>
  9. </VirtualHost>
  10. [root@server conf]# systemctl restart httpd

在windows下的host文件内写入域名与ip地址的映射

测试:

 2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料www.openlab.com/money 网站访问缴费网站

  1. [root@server conf]# mkdir /www/openlab/data
  2. [root@server conf]# echo 'data' > /www/openlab/data/index.html
  3. [root@server conf]# vim /etc/httpd/conf/httpd.conf
  4. <VirtualHost 192.168.95.131>
  5. DocumentRoot /www/openlab
  6. alias /data /www/openlab/data
  7. ServerName "www.openlab.com"
  8. </VirtualHost>
  9. <Directory /www/openlab>
  10. AllowOverride none
  11. require all granted
  12. </Directory>
  13. <Directory /www/openlab/data>
  14. AllowOverride none
  15. require all granted
  16. </Directory>
  17. [root@server www]# systemctl restart httpd

测试:

  1. [root@server data]# curl www.openlab.com/data/
  2. data

添加用户,增加密码访问控制

  1. [root@server ~]# mkdir /www/openlab/student/
  2. [root@server ~]# echo 'student' > /www/openlab/student/index.html
  3. [root@server data]# chmod 755 -R /www/openlab/student
  4. [root@server data]# useradd song
  5. [root@server data]# passwa song
  6. [root@server data]# useradd tian
  7. [root@server data]# passwd tian
  8. [root@server student]# htpasswd -c /etc/httpd/passwd song
  9. [root@server student]# htpasswd /etc/httpd/passwd tian
  10. [root@server student]# vim /etc/httpd/conf/httpd.conf
  11. <Directory /www/openlab/student>
  12. Authtype Basic
  13. AuthName "student"
  14. AuthUserFile /etc/httpd/passwd
  15. Require user song tian
  16. </Directory>
  17. [root@server student]# systemctl restart httpd

测试:

 

  1. [root@server student]# mkdir /www/openlab/money
  2. [root@server student]# echo 'money' > /www/openlab/money/index.html
  3. [root@server student]# chmod 755 -R /www/openlab/money
  4. [root@server student]# yum install mod_ssl -y
  5. [root@server student]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/openlab.key
  6. Enter PEM pass phrase:
  7. Verifying - Enter PEM pass phrase:
  8. [root@server student]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
  9. Enter pass phrase for /etc/pki/tls/private/openlab.key:
  10. You are about to be asked to enter information that will be incorporated
  11. into your certificate request.
  12. What you are about to enter is what is called a Distinguished Name or a DN.
  13. There are quite a few fields but you can leave some blank
  14. For some fields there will be a default value,
  15. If you enter '.', the field will be left blank.
  16. -----
  17. Country Name (2 letter code) [XX]:86
  18. State or Province Name (full name) []:shanxi
  19. Locality Name (eg, city) [Default City]:xi'an
  20. Organization Name (eg, company) [Default Company Ltd]:openlab
  21. Organizational Unit Name (eg, section) []:RHCE
  22. Common Name (eg, your name or your server's hostname) []:localhost
  23. Email Address []:1617995042@qq.com

  1. [root@server student]# vim /etc/httpd/conf/httpd.conf
  2. <VirtualHost 192.168.95.131:443>
  3. SSLEngine on
  4. SSLCertificateFile /etc/pki/tls/certs/openlab.crt
  5. SSLCertificatekeyFile /etc/pki/tls/private/openlab.key
  6. ServerName 192.168.95.131
  7. DocumentRoot /www/openlab
  8. alias /money /www/openlab/money
  9. </VirtualHost>
  10. <Directory /www/openlab/money>
  11. AllowOverride none
  12. require all granted
  13. </Directory>
  14. [root@server student]# systemctl restart httpd
  15. 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/871923
    推荐阅读
    相关标签