ubuntu下apache2指定端口创建虚拟站点过程记录
最近做个网站,所以安装了apache2,网站必须在根目录下运行,所以只能在测试机器上指定端口创建虚拟站点。
定端口创建虚拟站点过程如下:
- 打开终端安装apahce
sudo apt-get install apache2
- 转到配制目录
cd /etc/apache2 - 转到虚拟站点配制目录
cd sites-available/ - 拷贝默认站点
sudo cp 000-default.conf 你的文件名.conf - 编辑文件
sudo gedit 你的文件名.conf - 内容大致如下
<VirtualHost *:8082>
ServerAdmin webmaster@localhost
DocumentRoot 你的站点目录路径
<Directory 你的站点目录路经/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Order deny,allow
Allow from all
Satisfy all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- 说明:
- DocumentRoot路径后不带/,Directory路径后带/
- Allow from all必须有的
- 编辑上级目录中的端口配制文件
sudo gedit ../ports.conf - 添加内容
Listen 8081 - 在上级目录sites-enabled中建立链接
sudo ln -s 你的文件名.conf ../sites-enabled/你的文件名.conf - 重启apache
sudo /etc/init.d/apache2 restart
打开浏览器 http://127.0.0.1:8081/看一下成果吧