1、sudo apt-get install apache2
2、 sudo service apache2 restart
然后在页面上输入http://localhost,如果页面显示It works则表示成功
3.ubuntu下的/etc/apache2文件夹里可能没有httpd.conf。如果没有,则在apache2.conf里加上一行“Include httpd.conf”
4.httpd.conf里配跳转,例如:
<IfModule proxy_module>
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</IfModule>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName style.c.aliimg.com
DocumentRoot /home/yuangy/linux/style
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ http://110.75.196.23$1 [L]
</IfModule>
</VirtualHost>
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</IfModule>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName style.c.aliimg.com
DocumentRoot /home/yuangy/linux/style
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ http://110.75.196.23$1 [L]
</IfModule>
</VirtualHost>
5.重启服务如果成功,则http://localhost页面一样显示成功
6.其他可能碰到的问题:
如果localhost页面显示Forbidden,则在apache2.conf里的<Directory />...</Directory>中去掉Require all denied
如果本地没有的文件不能自动跳转到线上,检查mods-enabled文件里有没有mod_rewrite.load,若没有则从mod_available文件夹里拷贝过去