Ubuntu Web服务器网站首页存放路径

        Ubuntu 环境下使用Apache2配置Web服务器,如果服务器的内网ip地址为192.168.1.111,则在启动Apache2服务后,在浏览器输入192.168.1.111会看到主页显示Apache2 Ubuntu Default Page,如下图:


那么,如何替代这个首页呢?


首先,Apache2配置后会会指向一个目录/var/www/html,这个目录下会产生一个index.html,这个单网页文件就是上面看到的首页Apache2 Ubuntu Default Page。如果用WordPress见网站,其实整个WordPress目录就是放在/var/www/html下的。这里假设有两个网站WP001和WP002,那么此时/var/www/html目录下就会有一个文件和两个目录,分别是index.html、目录WP001和目录WP002,这些解析到浏览器的结果如下:


/var/www/html/index.html                                对应网址:http://192.168.1.111
/var/www/html/WP001/index.php                  对应网址:http://192.168.1.111/WP001
/var/www/html/WP002/index.php                  对应网址:http://192.168.1.111/WP002


以上就是网址对应规律,如果有域名并解析,那就是把192.168.1.111换成域名。


1、简单的单文件替代方法


想要将主页从替换Apache2 Ubuntu Default Page替换成自己的首页就很简单了,现将/var/www/html原来的index.html备份,然后将自己的主页单文件改名为index.html拷贝到/var/www/html目录下即可。


2、替换成网站首页


假设上面例子中,给WP001解析域名www.1234.com;WP002解析域名www.5678.com,那就是有两个网站在这台服务器。


那么,先在/etc/apache2下新建一个httpd.conf配置文件。


cd /etc/apache2
sudo gedit httpd.conf


然后,写入:


<VirtualHost *:80>
ServerName www.1234.com
DocumentRoot /var/www/html/WP001
DirectoryIndex index.php
</VirtualHost>


<VirtualHost *:80>
ServerName www.5678.com
DocumentRoot /var/www/html/WP002
DirectoryIndex index.php
</VirtualHost>


保存退出。


回到/etc/apache2修改apache2.conf


sudo gedit apache2.conf


添加一行
Include httpd.conf


保存退出。


重启apache2服务


sudo service apache2 restart


猜你喜欢

转载自blog.csdn.net/stlinax/article/details/80295850
今日推荐