如何启用虚拟主机进行本地开发

时间:2018-11-23 09:55:33

标签: php apache .htaccess

我想从另一个端口访问我的ubuntu机器中的文件夹。如果我在浏览器中键入localhost:81,它应该向我显示文件夹中的内容。并在浏览器上显示欢迎消息。

现在,我在html文件夹中创建了一个文件夹,该文件夹仅显示欢迎消息。如果我访问localhost / site,它会正确显示预期的结果。所以我做了一些更改。

我在里面创建了一个文件

  

/ etc / apache2 / sites-available

名为site.conf,其中包含以下内容。

<VirtualHost *:81>
<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

制成

sudo a2ensite site.conf                                
Enabling site site.
To activate the new configuration, you need to run:
  service apache2 reload
service apache2 reload
 * Reloading web server apache2                                                                                                                  * 

然后我访问了http://localhost:81/,它向我抛出了一个错误This site can’t be reached,其中http://localhost/site/正确地向我显示了欢迎消息。我在哪里出错了,该如何解决此问题?

1 个答案:

答案 0 :(得分:0)

更改您的/etc/apache2/ports.conf
Listen 80
Listen 81

如果您的apache进程似乎挂起了,请杀死所有的apache进程

ps -aux|grep
kill -9 PISs

然后启动apache服务器

sudo service apache2 start
相关问题