个人工具

“UbuntuHelp:LocalhostSubdomain”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:LocalhostSubdomain}}
 
{{Languages|UbuntuHelp:LocalhostSubdomain}}
 
Seting up Virtual Hosts on [[UbuntuHelp:ApacheMySQLPHP|Apache]] with subdomains of localhost allows you to access your local files as if you had different subdomains, eg site1.localhost/ and site2.localhost/
 
Seting up Virtual Hosts on [[UbuntuHelp:ApacheMySQLPHP|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.
 
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 ===
 
=== Hosts ===
 
In the Network Configuration Applet, go to the 'Hosts' tab and edit the entry for 127.0.0.1:
 
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  
 
* IP address: 127.0.0.1  
 
* Aliases: add 'site2.localhost'
 
* Aliases: add 'site2.localhost'
 
 
Alternatively, you can edit /etc/hosts directly, adding a line such as:
 
Alternatively, you can edit /etc/hosts directly, adding a line such as:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
127.0.0.1 site2.localhost
 
127.0.0.1 site2.localhost
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Apache ===
 
=== 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 <code><nowiki>a2ensite</nowiki></code> (which is similar to create a SymbolicLink to the site in /etc/apache2/sites-enabled).
 
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 <code><nowiki>a2ensite</nowiki></code> (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 <code><nowiki>a2dissite</nowiki></code> (or delete the symbolic link in /etc/apache2/sites-enabled).
 
This leaves the default configuration untouched. To revert, simply use the command <code><nowiki>a2dissite</nowiki></code> (or delete the symbolic link in /etc/apache2/sites-enabled).
 
 
<pre><nowiki>gksudo gedit /etc/apache2/sites-available/myconfig
 
<pre><nowiki>gksudo gedit /etc/apache2/sites-available/myconfig
 
</nowiki></pre>
 
</nowiki></pre>
 
 
The text in your new file should be something like this...
 
The text in your new file should be something like this...
 
 
<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/>
 
Options Indexes FollowSymLinks MultiViews +Includes
 
Options Indexes FollowSymLinks MultiViews +Includes
第38行: 第27行:
 
</Directory>
 
</Directory>
 
</VirtualHost></nowiki></pre>
 
</VirtualHost></nowiki></pre>
 
 
 
Then do:
 
Then do:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo a2ensite myconfig
 
sudo a2ensite myconfig
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Finally, restart Apache to apply changes:
 
Finally, restart Apache to apply changes:
 
<pre><nowiki>
 
<pre><nowiki>

2007年11月30日 (五) 20:08的版本

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