Apache配置
https://httpd.apache.org/docs/2.4/vhosts/examples.html
- 1.编辑:/opt/apache/httpd-2.4.54/conf/httpd.conf
- # Ensure that Apache listens on port 80
- Listen 80
- <VirtualHost *:80>
- DocumentRoot "/opt/apache/website/myweb001"
- ServerName www.example.com
-
- # Other directives here
- <Directory "/opt/apache/website/myweb001">
- Options Indexes FollowSymLinks
- AllowOverride None
- Require all granted
- </Directory>
- </VirtualHost>
-
- <VirtualHost *:80>
- DocumentRoot "/opt/apache/website/myweb002"
- ServerName www.example.org
-
- # Other directives here
- <Directory "/opt/apache/website/myweb002">
- Options Indexes FollowSymLinks
- AllowOverride None
- Require all granted
- </Directory>
- </VirtualHost>
- 注意:/opt/apache/website/myweb001和/opt/apache/website/myweb002为静态网站在虚拟机中的路径
-
- 2.重启Apache:httpd -k restart
-
- 3.防火墙打开端口权限:firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload
-
- 4.编辑:C:\Windows\System32\drivers\etc\hosts
- 192.168.1.97 www.example.org
- 192.168.1.97 www.example.com
-
- 解释说明:
- C:\Windows\System32\drivers\etc\hosts为主机hosts文件,可以将域名www.example.org和www.example.com
- 映射为虚拟机ip,主机浏览器输入www.example.org和www.example.com等价于输入192.168.1.97,http的默认端口
- 为80,主机浏览器输入192.168.1.97等价于输入192.168.1.97:80,这样就可以定位到虚拟机Apache服务,然后根据主
- 机浏览器输入的域名找到对应的ServerName为所输入域名的VirtualHost,这样就可以访问到对应的静态网站了,实际
- 应用中静态网站部署在云服务器,只需要将购买的域名解析为云服务器的公网ip即可