第一步:
/etc/apache2/ports.conf
添加新的端口,如:
Listen 8099
第二步:
/etc/apache2/sites-available 目录下新建文件
如:test.com.conf ( ServerName + .conf) 内容如下
<VirtualHost 127.0.0.1:8099>
// 自定义ServerName
ServerName test.com
ServerAdmin webmaster@localhost
// 设置 header (需要运行命令 a2enmod header)
Header set Access-Control-Allow-Origin http://www.fu51.cn,https://www/fu51.cn
// Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Allow-Methods GET,POST,OPTIONS
Header set Access-Control-Allow-Headers x-requested-with,lang,Origin,origin-secret,referer,content-type
// 自定义网站根目录
DocumentRoot /var/www/test/public/
<Directory /home/www/test/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存并执行以下命令:
sudo a2ensite test.com.conf #上面的文件名去掉 .conf
sudo service apache2 restart
如果路由失效
修改以下文件: Override None 这一项改为 AllowOverride All