1、2个文件夹
/etc/apache2/sites-avaliable/ 才是配置文件目录
/etc/apache2/sites-enabled/ 配置文件创建软连接到这个目录下,配置文件才生效
2、 创建配置文件
在sites-avaliable目录下
sudo cp 000-default.conf gongsc.conf #gongsc.conf 自己配置文件名
3、修改配置文件:gongsc.conf 只贴需要修改的代码
#域名
ServerName www.gongsc.com
ServerAdmin webmaster@localhost
#入口文件目录
DocumentRoot /var/www/gongsc/public
ErrorLog /var/www/html/gongsc/error.log
CustomLog /var/www/html/gongsc/access.log combined
<Directory "/var/www/gongsc/public">
Options FollowSymLinks
DirectoryIndex index.php index.html index.htm
#注意这个地方的配置,会影响本地目录下的.htaccess的启用。使用 All
AllowOverride All
Order deny,allow
Allow from All
</Directory>
4、创建链接使配置文件生效
sudo ln -s /etc/apache2/sites-available/gongsc.conf /etc/apache2/sites-enabled/gongsc.conf
5、重启Apache服务器
sudo service apache2 restart
6、修改hosts(/etc/hosts)
127.0.0.1 www.gongsc.com
7、如果需要对目录级的URL重写支持,安装模块rewrite_module
sudo a2enmod rewrite
ps:安装模块rewrite_module后,运行项目就不会出现 The requested URL /regiser was not found on this server.