特殊:Badtitle/NS100:LocalhostSubdomain:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Oneleaf留言 | 贡献
新页面: {{From|https://help.ubuntu.com/community/LocalhostSubdomain}} {{Languages|UbuntuHelp:LocalhostSubdomain}} Seting up Virtual Hosts on Apache with subdomains o...
 
Oneleaf留言 | 贡献
无编辑摘要
第29行: 第29行:
<pre><nowiki><VirtualHost *>
<pre><nowiki><VirtualHost *>
DocumentRoot /home/username/mysite/
DocumentRoot /home/username/mysite/
ServerName site2.localhost  
ServerName site2.localhost


<Directory /home/username/mysite/>
<Directory /home/username/mysite/>

2007年11月21日 (三) 18:52的版本

{{#ifexist: :LocalhostSubdomain/zh | | {{#ifexist: LocalhostSubdomain/zh | | {{#ifeq: {{#titleparts:LocalhostSubdomain|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:LocalhostSubdomain|1|-1|}} | zh | | }}

Seting up Virtual Hosts on Apache with subdomains of localhost allows you to access your local files as if you had different subdomains, eg site1.localhost/ and site2.localhost/

This is particularly useful if you're working on and testing several different websites on your system, and each one requires top-level folders for things such as ServerSideIncludes files and stylesheets.

Hosts

In the Network Configuration Applet, go to the 'Hosts' tab and edit the entry for 127.0.0.1:

  • IP address: 127.0.0.1
  • Aliases: add 'site2.localhost'

Alternatively, you can edit /etc/hosts directly, adding a line such as:

127.0.0.1	site2.localhost

Apache

Assuming you're using apache2, the cleanest thing to do is create a new configuration file in /etc/apache2/sites-available, and then enable the new site with the command a2ensite (which is similar to create a SymbolicLink to the site in /etc/apache2/sites-enabled).

This leaves the default configuration untouched. To revert, simply use the command a2dissite (or delete the symbolic link in /etc/apache2/sites-enabled).

gksudo gedit /etc/apache2/sites-available/myconfig

The text in your new file should be something like this...

<VirtualHost *>
	DocumentRoot /home/username/mysite/
	ServerName site2.localhost

	<Directory /home/username/mysite/>
		Options Indexes FollowSymLinks MultiViews +Includes
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
</VirtualHost>


Then do:

sudo a2ensite myconfig

Finally, restart Apache to apply changes:

sudo /etc/init.d/apache2 restart